I have a series of cron jobs on a server machine. I know I can redirect their stdout/stderr output to a file. If I redirect several cronjob outputs to the same file, will that work even if some of the jobs might be running at the same time?

link|improve this question
feedback

2 Answers

No, it's likely that they will overwrite each other.

As a simple method add

MAILTO=you@yourdomain.com

at the top of the crontab, then cron will email any output to you.

A more complex method may involve setting up cronolog listening on a FIFO then sending the output of those scripts to the fifo. This would take some care and handling, if the FIFO goes down then your cron jobs will block writing to it.

To be honest, I prefer cron jobs that output nothing unless there is a problem, in which case MAILTO lets me know.

link|improve this answer
feedback

even simpler method is to pipe all output into 'logger' tool and log to syslog, i.e.

* * * * * cronjob1.sh 2>&1 | logger -t cronjob1
* * * * * cronjob2.sh 2>&1 | logger -t cronjob2

then look in /var/log/messages

the disadvantage is that this is machine wide and you have to be root to be able to see the log, although it is possible to set up separate syslog files with user accessible permissions.

link|improve this answer
Awesome use of logger! – Dave Cheney Feb 25 '10 at 8:22
feedback

Your Answer

 
or
required, but never shown