Skip to content

Instantly share code, notes, and snippets.

@coldfire-x
Created November 30, 2012 05:57
Show Gist options
  • Save coldfire-x/4174003 to your computer and use it in GitHub Desktop.
Save coldfire-x/4174003 to your computer and use it in GitHub Desktop.
nginx rotate log, remove archive logs older than 2 weeks
#!/bin/bash
ARVDATE=`date +%Y%m%d%H%M`
PID=/usr/local/nginx/nginx.pid
cd /usr/local/nginx/logs
for log in sdf.access.log error.log
do
file=lastweek/arv$log$ARVDATE.log
mv $log $file
kill -USR1 `cat $PID 2>/dev/null` 2>/dev/null
gzip $file
# remove files older than 14days
find /usr/local/nginx/logs/lastweek/ -type f -mtime +14 -exec rm '{}' \;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment