Skip to content

Instantly share code, notes, and snippets.

@venj
Created May 21, 2011 00:57
Show Gist options
  • Save venj/984101 to your computer and use it in GitHub Desktop.
Save venj/984101 to your computer and use it in GitHub Desktop.
A simple logroll for my vps
# Add this script to root's cron
# Do it every sunday.
# 0 0 * * 0 /path/to/logroll.sh
function roll_log {
if [ $(ls -s $1 | cut -d' ' -f1) -gt '10240' ]; then
ts=$(date +%s)
mv $1 ${1}.$ts
if [ $? -ne 0 ];then
exit 1
fi
touch $1
tar cjf ${1}.${ts}.tar.bz2 ${1}.$ts
rm ${1}.$ts
fi
}
roll_log 'access.log'
roll_log 'error.log'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment