27.5. logroll

A few of the logs on my system grow quite quickly. Having to manually check the size of these logs for file sizes and then roll over the log (usually with a data stamp) gets tedious. Therefore I decided it was time I set up a script to do this automatically. The script would run from cron, and if any of the logs reached a certain size, the guilty log would be rolled over and a new log file created.

The script can easily be amended to suit other logs. For my system logs, I use another script, which is run once a week and truncates the log files. If I need to go back over any period I just check my backup; as I run a 16-week cycle this is no problem.

A size limit is defined in the variable BLOCK_LIMIT. This figure is the block size, ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.