Skip to content

Instantly share code, notes, and snippets.

@rrrodrigo
Created November 16, 2011 16:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrrodrigo/1370523 to your computer and use it in GitHub Desktop.
Save rrrodrigo/1370523 to your computer and use it in GitHub Desktop.
Rotation of Nginx logs with a twist
#!/bin/bash
YEAR=`date "+%Y"`
MONTH=`date "+%m"`
DAY=`date "+%d"`
LOG_FILES="access.log error.log"
DATE=$YEAR/$MONTH/$DAY
NGINX_LOG_ROOT=/var/log/nginx
# make path
mkdir -p $NGINX_LOG_ROOT/$DATE
# touch and symlink in new log files
for FILE in $LOG_FILES; do
LOG_FILE=$NGINX_LOG_ROOT/$DATE/$FILE
touch $LOG_FILE
ln -fs $LOG_FILE $NGINX_LOG_ROOT/$FILE
done
# tell nginx to re-open its log files
kill -USR1 `cat /var/run/nginx.pid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment