Created
June 30, 2012 16:10
-
-
Save serihiro/3024409 to your computer and use it in GitHub Desktop.
Log lotation script
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 | |
# | |
# 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