How to monitor a crontab job
The reliable way to monitor a plain crontab job is a dead man's switch: the job pings an external URL on success, and a monitor alerts you when that ping doesn't arrive in the expected window. This works because cron itself never tells you when a job fails or stops running — it discards output by default and sends no external alert. Append the ping to your crontab line with `&&` so it fires only on a clean exit.
Why can't cron tell me when a job fails?
cron runs your job with a minimal environment and discards its output unless you redirect it. A non-zero exit produces no notification, and a job that never runs (a removed crontab line, a rebooted box, a disabled account) leaves no trace at all. cron can mail output to the local user's mailbox via MAILTO, but that requires a working mail transfer agent and a mailbox someone actually reads — rare on modern servers.
How do I add a heartbeat to a crontab line?
Append a curl to the crontab entry with `&&` so the ping runs only if the job exits 0. If the job fails or never runs, no ping arrives and the monitor alerts:
# Ping only on success (&&, not ;). A failed job sends no ping.
0 3 * * * /usr/local/bin/nightly.sh && curl -fsS -m 10 --retry 3 "https://ping.cronshield.com/<your-check-id>"For anything more than a one-liner, wrap the work in a script with strict error handling so a failed step aborts the run instead of masking it:
#!/usr/bin/env bash
set -euo pipefail
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH" # cron's PATH is minimal
run_the_real_work
curl -fsS -m 10 --retry 3 "https://ping.cronshield.com/<your-check-id>" # only reached on full successHow do I confirm the crontab entry is actually installed?
crontab -l # list the current user's crontab
grep -R "nightly" /etc/cron* # system crontabs and cron.d drop-ins
# Confirm the cron daemon is running:
systemctl status cron 2>/dev/null || systemctl status crondA missing crontab line explains every run that stopped. On paid tiers, CronShield reads the captured output of a failing run and adds the last log line and a likely cause to the alert.
Add a missed-run alert to this job
The free tier gives you a heartbeat endpoint and an email alert when an expected ping doesn't arrive. Paid tiers add the log-aware diagnosis — the last log line and a likely cause in the alert. The heartbeat receiver ships in an upcoming release; see the plans to learn what each tier adds.
Frequently asked questions
- Should I use && or ; to add a heartbeat to my cron job?
- Use &&. With &&, the ping runs only if the job exited 0, so a failure correctly withholds the ping and triggers an alert. With ;, the ping runs regardless of outcome — even after a failure — which hides the very outage you're monitoring for.
- Why does MAILTO not email me about cron failures?
- MAILTO only works if a mail transfer agent is installed and configured to deliver the local mail cron generates, and it mails all output (not just failures) to a local mailbox that's usually unread. An external heartbeat monitor is more reliable and also catches the case where the job never ran at all.