How to check if a cron job ran (and get told when it doesn't)
On this page
To check whether a cron job ran, search the cron log: grep CRON /var/log/syslog on Debian and Ubuntu with rsyslog, journalctl -u cron on systemd-only systems, or /var/log/cron on RHEL and Fedora. That proves cron started the command, not that it worked. To know it worked, have the job record or report its own exit code, and to hear when it didn't run at all, add a heartbeat check that alerts when the report is late.
Last night's backup should have run at 03:00. Did it? There are two questions hiding in there: did cron start it, and did it work. Cron's logs can answer the first one. Only the job can answer the second.
Did cron start it? Check the cron log
Cron logs through the system logger, under the cron facility. Where that ends up depends on the distribution.
Debian and Ubuntu with rsyslog:
grep CRON /var/log/syslog
Debian 12 and other systems that use only the systemd journal. Debian 12 doesn't install rsyslog by default, so there may be no /var/log/syslog at all. Ask the journal instead:
journalctl -u cron --since "today 02:50" --until "today 03:10"
RHEL, Rocky, Alma and Fedora with rsyslog. The default rsyslog rules send cron messages to their own file:
grep backup /var/log/cron
If you find a line for your job at 03:00, cron started it. If there's nothing, check that the crontab you're reading is the one on this machine and this user (crontab -l, or sudo crontab -l -u backup), and that the cron service is running.
Why the log doesn't prove it worked
By default, Debian's cron logs when a job starts, not how it ended. A job that crashed one second in looks exactly like one that finished perfectly. Two changes make the log useful:
- Keep the job's own output. Cron mails output if mail is set up, and drops it otherwise. Append it to a file instead:
0 3 * * * /opt/jobs/backup.sh >> /var/log/backup.log 2>&1
- Write down the exit code. Add one line after the job:
0 3 * * * /opt/jobs/backup.sh >> /var/log/backup.log 2>&1; code=$?; echo "$(date -Is) exit=$code" >> /var/log/backup.log
Save the code in a variable first: in some shells $? changes after the $(date ...) runs. And use date -Is rather than a format like date +%F, because an unescaped % ends the command in a crontab line. See why cron jobs fail silently.
Now tail /var/log/backup.log tells you whether the 03:00 run finished, and with what code.
Cron inside a Docker container
Many container images don't run a syslog daemon, so cron's log lines have nowhere to go and there's no /var/log/syslog to grep. If your job runs in a container:
- send the job's output to the container's main output, for example by appending
>> /proc/1/fd/1 2>&1to the crontab line, so it shows indocker logs - check that cron is actually running in the container (
ps aux | grep cron); a rebuilt image without the cron process runs nothing and logs nothing
Stop checking by hand
Everything above answers "did it run" after the fact, when you think to look. Flip it around: have the job report after every run, and get told when a report says it failed or doesn't arrive.
With Stallbell, create a monitor with the same schedule as the job, then add the ping to the end of the crontab line:
0 3 * * * /opt/jobs/backup.sh >> /var/log/backup.log 2>&1; curl -fsS -m 10 --retry 3 https://stallbell.com/p/TOKEN/$?
- Exit code 0 counts as a success. Any other code from 1 to 255 is a failure, and by default the first failure sends a Failed run alert.
- If nothing arrives by 03:00 plus the grace period (5 minutes unless you change it), you get a Missed run alert. Stallbell starts watching for this after the first check-in.
- The monitor page lists recent runs with their status and time, so "did it run last night" is one click.
Alerts go by email, Slack or a signed webhook. For a full setup, including a wrapper that also catches hung jobs, see how to monitor cron jobs.
FAQ
How do I see when a cron job will run next? Cron doesn't print it. Read the five time fields in crontab -l. A Stallbell monitor on a cron schedule lists the next three expected runs in its schedule timezone.
The log shows the job started, but nothing happened. Why? Usually PATH or environment: cron runs with a short PATH and none of your shell's exports. Test with env -i PATH=/usr/bin:/bin /bin/sh -c 'your command'. More causes are in why cron jobs fail silently.
Can I get cron to log when a job ends? Debian's cron has a -L option for that (2 logs job ends, 4 logs failed jobs), set through /etc/default/cron. It still only shows what cron can see from outside the job.
Does Stallbell read my logs? No. It only knows what the job sends in the ping.
Start with last night's job
Pick the job you just went looking for, add the ping, and next time you'll know before you have to look.
Related: How to monitor cron jobs · Why cron jobs fail silently · Postgres nightly backup