Your cron job stopped running 3 weeks ago. Here's how to find out in 5 minutes instead.
Cron has one failure mode that hurts more than any crash: it fails silently. The backup script exits 1, the server is rebuilt without the crontab, or someone comments out a line "for a minute". Nothing errors and nothing alerts. You find out when you need the backup.
An HTTP uptime check can't catch this, because there is nothing to check from outside. The fix is to flip the direction: the job reports in, and silence is the alert. This pattern is called heartbeat monitoring (also known as a dead man's switch).
The pattern
- Create a unique URL for each job.
- The job calls that URL when it finishes successfully.
- If no call arrives within the expected interval plus a grace period, you get alerted.
It catches every way a job can disappear: the crontab is gone, cron isn't running, the host is down, the job hangs, or the job exits early.
Ping only on success
The most common mistake is pinging unconditionally:
# Wrong: pings even when the backup fails 0 2 * * * /opt/scripts/backup.sh; curl -fsS https://example.com/ping Use && so the ping only happens when the script exits 0:
0 2 * * * /opt/scripts/backup.sh && curl -fsS -m 10 --retry 3 https://example.com/ping > /dev/null -
-fmakes curl fail on HTTP errors instead of printing an error page -
-sSis silent, but still shows errors -
-m 10 --retry 3stops a slow monitoring endpoint from hanging your cron
Report failures explicitly
Waiting for silence means waiting a full interval. If the job knows it failed, say so immediately and include the exit code:
#!/bin/bash BASE="https://example.com/ping/YOUR_TOKEN" curl -fsS -m 10 "$BASE/start" > /dev/null /opt/scripts/backup.sh code=$? if [ "$code" -eq 0 ]; then curl -fsS -m 10 "$BASE?exit_code=0" > /dev/null else curl -fsS -m 10 "$BASE/fail?exit_code=$code" > /dev/null fi exit "$code" The /start call lets the monitor measure run duration. A job that normally takes 2 minutes and suddenly takes 40 is worth knowing about before it starts overlapping with itself.
Pick the grace period honestly
| Job schedule | Expected interval | Grace period |
|---|---|---|
| Every 5 minutes | 5 min | 2–5 min |
| Hourly | 1 h | 10 min |
| Nightly backup | 24 h | 30–60 min |
| Weekly report | 7 d | 2–4 h |
Set the grace period to slightly more than the job's longest normal run time. If it's too tight you'll get false alarms, and you'll start ignoring them.
Things that still bite people
- Cron's environment is minimal.
PATHis usually/usr/bin:/bin, socurlmay not be found on some systems. Use absolute paths, or setPATH=at the top of the crontab. - Timezones. Cron uses the system timezone. A server moved to UTC shifts every job, and your heartbeat will catch it.
- Overlapping runs. Wrap long jobs in
flock -n /tmp/job.lockso a slow run doesn't stack up. - Pinging from inside a
tryblock. In application code, ping after the work commits, not before.
Tools
You can build this yourself with a tiny endpoint and a timer, but the timer is the hard part: it has to be reliable when your infrastructure isn't. Hosted options like UptimeIO, which I work on. UptimeIO's free plan includes heartbeat monitors next to regular website and API uptime monitoring. Whichever you pick, the && and /fail patterns above work the same way.
How do you monitor your scheduled jobs? I'm curious whether anyone still relies on MAILTO.