Wednesday, July 14, 2010

Simple Bash script to rotate log

If you have some program that doesn't handle its own log rotation, you could use the below script to rotate the log. Ideally, you would call this script in a daily crob job.

if [ ! -f $logfile ]; then
echo "log file not found $logfile"
exit 1
timestamp=`date +%Y%m%d`
cp $logfile $newlogfile
cat /dev/null > $logfile
gzip -f -9 $newlogfile
Post a Comment