Skip to content

Instantly share code, notes, and snippets.

@holysugar
Created April 20, 2011 07:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save holysugar/930621 to your computer and use it in GitHub Desktop.
Save holysugar/930621 to your computer and use it in GitHub Desktop.
nginx log rotation script
#!/bin/bash
LOGDIR=/usr/local/nginx/logs
PID=/usr/local/nginx/logs/nginx.pid
NOW=$(date +%Y%m%d-%H%M%S)
cd ${LOGDIR}
for i in *.log; do
mv ${i} ${i}.tmp.${NOW}
done
kill -USR1 $(cat ${PID})
sleep 1 #FIXME sleep time
if ls *.log >/dev/null 2>&1; then
for i in *.log.tmp.${NOW}; do
newfile=${i/.log.tmp.${NOW}/-${NOW}.log}
mv $i $newfile
bzip2 $newfile
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment