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?

link|improve this question

25% accept rate
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
feedback

1 Answer

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.

link|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
feedback

Your Answer

 
or
required, but never shown

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