Bash Log Rotate Script

Ever need to do some simple logging from stdout and not want to do full syslog logging? Then this simple script may be the answer. Hopefully this will save some one else a few minutes work!

Instead of doing:

Where myProgram’s stdout will write to log.out forever until your entire hard disk fills up you can use this script instead:

Where log.out is the log file you want to write to and 10000 is the amount of lines you want the log file to grow to before rotating. This will store a maximum of 10 log files.

The source of logger.sh:

You can download it here here: logger.sh

Obviously dont forget to set your execute bit:

 

Posted in Linux