Created
August 31, 2017 09:43
-
-
Save lovelock/69bf694e64c85c05ba1060e8536d7c7e to your computer and use it in GitHub Desktop.
script to rotate nginx access/error log depending on current date, it should be run at 00:00
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
#!/usr/bin/env bash | |
YESTERDAY=$(date -d'1 days ago' +%Y%m%d) | |
for log in /data/log/nginx/*.log; do | |
mv ${log} ${log}.${YESTERDAY} | |
done | |
kill -USR1 `cat /run/nginx.pid` | |
sleep 1 | |
for old_log in /data/log/nginx/*.${YESTERDAY}; do | |
zip ${old_log}.gz ${old_log} | |
rm ${old_log} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment