How to monitor cron jobs (and get alerted when they fail)
Cron has no idea whether your job did its work. It starts the command and moves on. If the job crashes, hangs, or never starts, nobody hears about it until the backup you needed isn't there.
Three ways cron jobs fail silently
- The job never runs. The server was rebooted and crond didn't come back, the crontab was overwritten during a deploy, the container that held it was replaced, or the schedule has a typo (
0 0 31 2 *never fires). - The job runs but fails. A missing environment variable (cron runs with a minimal
PATH), an expired credential, a full disk. Output goes to local mail that nobody reads. - The job hangs. A network call without a timeout, a lock that never releases. No error is ever written because the process never exits.
Logging exit codes catches the second case only. Case one produces no log line at all, and case three produces nothing until someone notices.
The fix: a heartbeat (dead man's switch)
Turn the check around. Instead of watching for errors, expect a signal. At the end of each successful run, the job calls a URL. A monitor knows how often that should happen. If the signal is late, the monitor alerts you. All three failure modes look the same from the outside: the ping didn't arrive.
0 3 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://rtekfsmupinxncwigmnf.supabase.co/functions/v1/api/ping/YOUR_KEY
The && matters: the ping is only sent if the script exits with 0. -m 10 stops a slow network from hanging your job, and --retry 3 rides out a blip.
Choosing the period and grace time
- Period = how often the job is scheduled. Daily at 03:00 → 1 day.
- Grace = how long a normal run can take, plus a margin. A backup that takes 20 minutes → 1 hour grace.
Too little grace gives false alarms; too much delays real ones. Start generous and tighten after a week of data.
Report failures explicitly
Waiting for a missed ping can mean hours of delay for a daily job. If your script knows it failed, say so right away:
if /srv/job.sh; then curl -fsS https://rtekfsmupinxncwigmnf.supabase.co/functions/v1/api/ping/YOUR_KEY; else curl -fsS https://rtekfsmupinxncwigmnf.supabase.co/functions/v1/api/ping/YOUR_KEY/fail; fi
Wrap a whole crontab line
*/10 * * * * cd /srv/app && timeout 300 ./sync.sh >> /var/log/sync.log 2>&1 && curl -fsS -m 10 https://rtekfsmupinxncwigmnf.supabase.co/functions/v1/api/ping/YOUR_KEY
timeout 300 turns a hang (failure mode three) into a non-zero exit, so the ping is skipped and you get alerted.
Other schedulers
The same pattern works for systemd timers (ExecStartPost=), Kubernetes CronJobs (a final container step), GitHub Actions schedule: workflows (a last step with if: success()), Windows Task Scheduler (Invoke-WebRequest), and serverless schedulers.
Set it up in two minutes
CronBeat is a free heartbeat monitor: create a check, copy its ping URL into your job, and add a Slack or Discord webhook for alerts. Five checks are free with no signup.