gzip log files older than one day

To Gzip files older than one day place this in a cronjob:

TODAY=`date +"%Y-%m-%d"`

for logfile in /var/log/tomcat6/*.log; do
# grab the %Y-%m-%d out of the name
DTS=${logfile:(-14):10}
if [ $DTS != $TODAY ]; then
# compress in place
gzip $logfile
fi
done

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.