Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Manage the periodic logs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Manage the periodic logs
Authored by: rflorence on Jul 25, '08 11:53:26AM
It is not a good idea to redirect the output of the periodic commands to /dev/null; valuable debugging and system information is lost forever. It is also not a good idea to turn an orderly Unix filesystem into spaghetti with symbolic links from system files to user directories. If the size of the periodic files is bothersome, they can be automatically rotated with a simple script installed as /etc/daily.local:
#!/bin/sh
# script to rotate logs
# to maintain historical logs, uncomment the three lines

rotatelog ()
{
    log=$1
    size=`ls -l $log | awk '{print $5}'`
    if [ $size -gt 50000 ] 
    then
#	[ -f $log.2.bz2 ] && mv $log.2.bz2 $log.3.bz2
#	[ -f $log.1.bz2 ] && mv $log.1.bz2 $log.2.bz2
#	[ -f $log.0.bz2 ] && mv $log.0.bz2 $log.1.bz2
	bzip2  $log.0.bz2 
	chmod 0644 $log.0.bz2
	> $log
    fi
}
cd /var/log
rotatelog daily.out
rotatelog weekly.out
rotatelog monthly.out
The script rotates the logs when they are >50K. If you uncomment the commented lines in the code, the script will save the four most recent versions of each log; otherwise it will save only the most recent log. The script is run automatically by the periodic daily command; probably best to install it with execution permission (chmod +x /etc/daily.local).

[ Reply to This | # ]