How can I make sure my cron jobs are really working and not just running?
Asked by
trolley stop
I've been dealing with cron monitors that say a job "ran successfully" but that doesn't guarantee it's doing what I need it to. I'm concerned about real outcomes like if the job returns an error, outputs nothing, takes way too long, or even runs but creates an empty file. All I get is a simple "ping received" status, which doesn't help at all. Is there a reliable way to check for exit statuses, runtime issues, or the validity of the output, or is it common for people to just implement their own solutions?
Answers
Your job should provide a status report on its own, regardless of the scheduler youโre using. Whether youโre on cron, systemd timers, or something else, having uniform output from the job itself is key. Start logging with something like syslogโit helps! It took me a good eight years to convince my team, but itโs worth it.
Reply to this answer
You can actually manage this pretty easily with a bash script! Itโs straightforward to capture errors and track job outputs effectively.
Reply to this answer
The reality is that if a job fails, it's often someone else's responsibility to deal with it. Cron just runs the commands you give it and doesn't do any checks for you. It's all about focusing on one task efficiently, in line with Unix philosophy.
Reply to this answer
Think about what "the job running successfully" actually looks like. Set up monitoring that checks your system state against expected outcomes. That way, you treat your cron jobs as interchangeable pieces without needing to change how you monitor them.
Reply to this answer
Add your answer
Answers are reviewed before publication.
!count me in: Do you have a simple example of your script? That could be really helpful!
sunroom.floor: True, that's fine for one job on one server, but once you've got multiple jobs across different servers, youโll really need good logging and alert systems in place. Otherwise, you might only find out something's broken when a user complains!