views:

72

answers:

2

My bash script produces a log file. Now i'd like to implement some log file rotation.
Let's say the first time it's called somelog.log, the next time it's renamed to somelog.log.1 and the new log file somelog.log.
The third time the new log is somelog.log again, but somelog.log.1 is renamed to somelog.log.2 and the old somelog.log to somelog.log.1.
I would be able to grant a maximum of eg 5.

Is this done before (sample script), any suggestions. I appreciate any advice.

+2  A: 

have a look at logrotate this should do exactly what you want. linuxers.org has a nice tutorial on how to use it.

Nikolaus Gradwohl
When i use **logrotate**, i'am depending on the time when the log files are rotated and not when my script runs. My script creates a log file per run and not a 'merged' log file.
Robertico
@Robertico: You should be able to specify the statefile and the configfile on the command line to `logrotate` and call it from your script to make it only rotate files you designate.
Dennis Williamson
Already answered.
Robertico
A: 

Already answered. here

Robertico