A cron job didn't run. Check these in order: is cron running, did it start the job, why it didn't, and whether the job itself failed. Each step has a command and a log line.
systemctl status cron # Debian, Ubuntusystemctl status crond # RHEL, Rocky, Almapgrep -a cron If it was stopped, the journal says when. Search for it:
journalctl -u cron | grep -i stop The lines to look for, from when we stopped cron on one of our servers ("Regular background program processing daemon" is cron on Debian and Ubuntu):
Dec 2 23:14:37 web01 systemd[1]: Stopping Regular background program processing daemon...Dec 2 23:14:37 web01 systemd[1]: Stopped Regular background program processing daemon.
If it's stopped, start it and make sure it starts on boot: systemctl enable --now cron.
Search for your command in /var/log/syslog (Debian, Ubuntu), /var/log/cron (RHEL) or the journal:
grep 'CMD (/usr/local/bin/backup.sh)' /var/log/syslog | tail -3journalctl -u cron --since today | grep backup.sh Cron logs a CMD line for every job it starts. This is what one looks like:
Dec 2 22:45:01 web01 CRON[18571]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1) No CMD line at the time it should have run: cron never started it, so the problem is the schedule, the file or cron itself (step 3). A CMD line at the right time: cron did its part, and the problem is inside the job (step 4).
A script in /etc/cron.daily that never runs. On Debian and Ubuntu, run-parts only runs files whose names are made of letters, digits, underscores and hyphens. backup.sh has a dot, so it's skipped without a word. Ask run-parts what it would run, and if your script isn't listed, rename it (backup) and check that it's executable:
run-parts --test /etc/cron.daily
A file in /etc/cron.d that's ignored. The same naming rule applies, so no dots: /etc/cron.d/backup.cron is ignored. The file also has to be owned by root and not writable by group or others. And each line in /etc/cron.d and /etc/crontab has a user field before the command, which a user crontab doesn't:
ls -l /etc/cron.d/chown root:root /etc/cron.d/backupchmod 644 /etc/cron.d/backup
cron.daily and anacron. On Debian and Ubuntu, /etc/crontab runs cron.daily with this line (the real one from our test server):
test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
If anacron is installed, cron skips it and anacron runs cron.daily instead, on its own schedule from /etc/anacrontab.
To see what starts anacron on your release: systemctl list-timers | grep -i anacron and ls /etc/cron.d.
A user crontab. List it as root. Two things catch people. A % in a crontab line is turned into a newline, so date +%F breaks the line: escape it as \% or move the command into a script. And cron runs with a minimal PATH, so a command that works in your shell may not be found: use full paths, or set PATH= at the top of the crontab.
crontab -l -u user1
A systemd timer, not cron. Some jobs you'd expect in cron run from systemd timers on current Debian and Ubuntu. Packaged jobs such as certbot and PHP's sessionclean ship both: a cron entry that exits when systemd is running, and a timer that does the work. So a CMD line for them doesn't mean the work happened, and a missing one doesn't mean it didn't. List the timers, then check one with journalctl -u <unit>:
systemctl list-timers We saw exactly this when we stopped cron for 19 hours.
Cron mails a job's output to the crontab owner, or to MAILTO if it's set. Without a mail program on the server, the output is thrown away. To keep it, send it to syslog in the crontab line:
0 2 * * * /usr/local/bin/backup.sh 2>&1 | logger -t backup
Debian and Ubuntu cron log it when they throw output away: (CRON) info (No MTA installed, discarding output).
Debian and Ubuntu cron can also log jobs that exit with an error (-L 4, see man cron), and the job's own log usually says why.
All of this assumes you know a job didn't run. If cron's lines go to a central log server, you can have it tell you: cron monitoring compares checking by hand, ping monitors and learning the schedule from the logs. Trunc does the last one: missing log alerts.
Questions about Trunc or a trial: email us at sales@noc.org.
We love logs. In this section we will share some articles from our team to help you get better at logging.
Logging for fun and a good night of sleep.
Latest articles from our learning center.
Do you have an idea for an article that is not here? See something wrong? Contact us at support@noc.org
14 days free trial. No credit card required.