Skip to content

Instantly share code, notes, and snippets.

@serihiro
Created June 30, 2012 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serihiro/3024409 to your computer and use it in GitHub Desktop.
Save serihiro/3024409 to your computer and use it in GitHub Desktop.
Log lotation script
#! /bin/sh
#
# This script excutes to archive log daily, and
# delete archived file whose timestamp is over day period you setted.
TODAY=`date +%Y-%m-%d`
#Directory you put logs. (ex '/home/app/program/log'
LOG_DIR=''
#Log file name you want to lotate. (ex 'info.log'
LOG_FILE_NAME=''
#Day of log retention period. (ex 7
LOG_RETENTION_PERIOD=7
cd $LOGDIR
tar -jcf ${LOG_FILE_NAME}.$TODAY.tar.bz2 ${LOG_FILE_NAME}
rm -f ${LOG_FILE_NAME}
find ./ -ctime +${LOG_RETENTION_PERIOD} -type f -exec rm -f {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment