Skip to content

Instantly share code, notes, and snippets.

@agushuley
Created February 9, 2012 08:40
Show Gist options
  • Save agushuley/1778521 to your computer and use it in GitHub Desktop.
Save agushuley/1778521 to your computer and use it in GitHub Desktop.
Archive and remove old log files, rotate nginx files
#!/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 {} \;
@agushuley
Copy link
Author

./clear-old-data cat $HOME/var/run/nginx.pid -USR1 $HOME/logs/*.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment