Created
February 9, 2012 08:40
-
-
Save agushuley/1778521 to your computer and use it in GitHub Desktop.
Archive and remove old log files, rotate nginx files
This file contains 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/sh | |
# Usage: ./clear-old-data `cat $HOME/var/run/nginx.pid` -USR1 $HOME/logs/*.log | |
if [ ! -z $1 ] ; then | |
_PID=$1 | |
shift | |
_SIG=$1 | |
shift | |
_YESTERDAY=`date -v -1d '+%Y-%m-%d'` | |
find $* -exec mv {} {}.$_YESTERDAY \; | |
kill $_SIG $_PID | |
fi | |
find $HOME/logs/ -mtime +30 -exec rm -f {} \; | |
find $HOME/logs/ -name '*-????-??-??.log' -mtime +2 -exec gzip {} \; | |
find $HOME/logs/ -name '*-.log.????-??-??' -mtime +2 -exec gzip {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./clear-old-data
cat $HOME/var/run/nginx.pid
-USR1 $HOME/logs/*.log