Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written a realtime bus tracking program that runs a cron every minute to check the service of the bus. In order to remove some server resources I am going to be creating an instance on PHPfog then croning it there. My Question is what's the best way to know if the cron failed and if so then run the local server copy as a backup?

share|improve this question
Why not check the results right inside crontab? Like, if /usr/bin/check_bus; then local_copy; fi ? – minaev Dec 13 '11 at 13:15
how is it real time if you run it every minute via cron?) – alexus Jul 24 '14 at 15:55

I redirect both of stdout and stderr to a log file:

*/15 * * * * /usr/bin/php bus_tracking.php >> /var/log/bus_tracking.log 2>&1

and use Nagios's check_logfiles plugin to monitor this log:

command[check_bus_tracking]=/usr/bin/sudo /usr/local/nagios/libexec/check_logfiles --tag=bus_tracking --logfile=/var/log/bus_tracking.log --criticalpattern="error|Permission denied" --warningpattern="warning"

You can also write an event handler to run the local server copy.

share|improve this answer
okay, now say that to a 5 year old :) – BandonRandon Dec 9 '11 at 8:08
What do you mean? – quanta Dec 9 '11 at 8:13
Just that some of that was over my head. I see that Nagios is a server monitor that i'm assuming I'd need to install first. – BandonRandon Dec 9 '11 at 8:15

Seems like it would be easier to use a service like If your cron job fails you'll get an alert. This way you'd only have to dig through log files when it really matters—after a failure.

share|improve this answer

Your Answer


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.