Blue Shrapnel

Sunday, September 17, 2006

Compress Log File Shell Script

To save space but retain logfile data, copy and compress logfiles and start again at 0. You could setup a cron job to do this monthly, etc. Or add a check on the size and only process this warranted. If necessary you may want to implement log rotation (see savelog or logrotate). This may already be implemented in FC5.

mv /var/log/messages /var/log/messages-backup
cp /dev/null /var/log/messages //truncate file to zero bytes
CURDATE='date + "%m%d%y"'
mv /var/log/messages-backup /var/log/messages-$CURDATE
gzip /var/log/messages-$CURDATE

0 Comments:

Post a Comment

<< Home