-
-
Save fengjing/6c7500c92c0899d686bd19f91fb1274c to your computer and use it in GitHub Desktop.
nginx log rotation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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