Cron – Being notified via email of errors in cron jobs

cronemail

You would like to be notified via email of errors occurring while executing cron jobs.

I use CentOS and the file /etc/crontab for the configuration.

The first step I have done is:

MAILTO=my_email_address

and then I have appended this to each crontab entry:

2>/dev/null

That means this

24 4 * * * root /usr/sbin/ntpdate pool.ntp.org

becomes:

24 4 * * * root /usr/sbin/ntpdate pool.ntp.org 2>/dev/null

In that way I should suppress the normal output and let error messages be sent.

I would like to know if you think what I have done is right and whether that has got any pitfall.

Thanks,
Dan

Best Answer

Actually, I think you've done the exact reverse of what you wanted; you've suppressed the error messages (by sending STDERR to /dev/null) and will get only the normal output.

Try

24 4 * * * root /usr/sbin/ntpdate pool.ntp.org > /dev/null

Better still, run ntpd; it's a much better way of keeping your clocks in sync than brute-force resetting them once a day.

Related Topic