gzip log files older than one day

December 19, 2011

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