views:

76

answers:

3

I have a script running in the background that prints some output. I redirected the standard output to a file for log purposes. However I don't want this file to grow forever, what would be a good way to do rollover without coding the logic myself? (Either rollover based on date or file size).

+1  A: 

logrotate(8)

anthony
This depends on the logging program to close and reopen the log after it is rotated.
Craig
`logrotate` can send a signal to the program which can trap and handle it. Easy enough.
Dennis Williamson
+5  A: 

Pipe the output into something like multilog it will handle all that stuff for you.

And example:

script_that_produces_output.sh |multilog s2000 ./logdir

will run the script capturing stdout to a file called ./logdir/current rotating it when it is bigger than 2000 bytes.

Craig
Can you give a brief example on ho wto use multilog?
erotsppa
A: 

As well as multilog, there's also a similar tool called svlogd from the runit suite. You may find that already packaged in your distro, since daemontools (multilog) has only recently become public domain.

camh