Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm concerned that cron jobs can fail silently for an indefinite period of time on vanilla Ubuntu Desktop 12.04.1 (Precise), and no one will notice. I would like to get a notification whenever a system cron job prints some output or just fails.

I know it is possible to install a mail server (e.g. postfix), configure it for local-only delivery, set up an alias so that root's mail is delivered to my normal user account and configure a mail client to check my local mailbox.

Are there any lightweight alternatives to this solution in Ubuntu?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

You could redirect the error output of your cronjob command to a file. Here is an example of a line in /etc/crontab:

01 3    * * *   user    /bin/command 2>> /var/log/some.file

Then at least you got a clue if errors occured. You might even write a script to notify you over notify-osd or similar tools when the file changes.

Edit:

The file /var/log/syslog reports messages from cron as well. You might want to take a look at that. To get a dedicated log-file for the cron deamon edit /etc/rsyslog.d/50-default.conf and uncomment/edit the line that says:

#cron.*             /var/log/cron.log

Don't know what you'll find there but worth the try. Report how it went.

share|improve this answer
    
Thanks. I'm worried about existing and future system cron jobs. So I'd rather not modify them all. That would hinder upgrades and would not cover any new cron jobs received as part of a package update. So I'm looking for a solution that would apply to all system cron jobs at once. –  Alexander Konovalenko Aug 24 '12 at 16:26
    
I'd be surprised if a solution existed outside of the usual mailer that fulfilled so many restraints –  con-f-use Aug 24 '12 at 17:08
add comment

"I would like to get a notification whenever a system cron job prints some output or just fails."

I'd recommend using some sort of cron monitoring tool. There are a few out there but I currently use Dead Man's Snitch (https://deadmanssnitch.com) and like it. It will alert you when a cron job doesn't check in. Like you're doing, just curl your unique snitch URL after the job and hit the url. There are a few others out there like probyapp but they aren't free...good luck.

share|improve this answer
add comment

Have you tried writing script? I'm sure there is an easy way like:

if cron.output = fail then notify-send "sorry bro"

share|improve this answer
    
Do you have an idea how to integrate such a script with cron? Modifying all system cron jobs one by one is not a good idea. I'm looking for a solution that would apply to all system cron jobs at once. –  Alexander Konovalenko Aug 24 '12 at 16:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.