How to check if a cron job is running, or ran

On this page

Three different questions hide in this one: did cron start the job, is it running now, and did it succeed. The system log answers the first, pgrep answers the second, and only the job itself can answer the third. This page gives the command for each, and the way to stop checking by hand.

How do you check that cron started the job?

Cron writes a line to the system log each time it starts a command. Search for your command in it:

shell
grep CRON /var/log/syslog | tail -n 20
journalctl -u cron --since "1 hour ago"

On Debian and Ubuntu the log is /var/log/syslog when the system keeps one, or the journal, and the unit is called cron. On Fedora and Red Hat the unit is crond and the file is /var/log/cron. A line shows the user and the command that cron launched. It shows that the job started, not that it worked. Where to find cron logs goes through each system.

How do you check whether a job is running right now?

shell
pgrep -af backup.sh
ps -eo pid,etime,cmd | grep '[b]ackup.sh'

pgrep -af lists the process ids and full command lines that match the name, and etime in the second form shows how long each one has been running. Two lines for one job mean two runs are overlapping; see overlapping cron runs. The brackets in [b]ackup.sh stop grep from matching itself.

How do you check that the job finished and succeeded?

Cron keeps no result. Make the job leave one. The simplest record is a file that is touched only when the work succeeded:

crontab
30 2 * * * /usr/local/bin/backup.sh && touch /var/run/backup.last-ok

Read its age with stat -c %y /var/run/backup.last-ok. A file older than the schedule allows means the job did not finish its last run. The exit status of the last command is the same signal that exit codes and failure signals describes.

How do you test that cron runs a new job at all?

Temporarily set the schedule to every minute and have the job write a line to a file, as in how to create a cron job. If the file grows once a minute, cron and the schedule are fine and the fault is in the real command. If it stays empty, check that the service is running with systemctl status cron and read cron job not running.

How do you stop checking by hand?

A log search tells you about the past only when you think to run it, and a job that never started leaves no line to find. A heartbeat check reverses it: the job reports each success, and an alert goes out when a report does not arrive on time. Add the request to the end of the line:

crontab
30 2 * * * /usr/local/bin/backup.sh && curl -fsS --max-time 10 --retry 5 -o /dev/null https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10

Create a check with the same schedule and CronMissed records each run and alerts you when one is late or fails. What is cron job monitoring? explains the three ways a job can fail, and start and finish pings shows how to see a job that is running too long.

Sources

Questions and answers

How can I tell if cron ran my job last night?
Search the system log for the command with grep CRON /var/log/syslog or journalctl -u cron. If the log has been rotated, look in the older files. The log proves the start, so a script that writes its own result is the better evidence.
How do I check if the cron service is running?
Run systemctl status cron, or systemctl status crond on Fedora and Red Hat. A machine that was off at the scheduled time did not run the job, and cron does not catch up on missed runs.
How do I know if a cron job ran twice?
Compare the process ids in the log lines for the job. Different ids mean separate runs. Two entries at the same time can also mean the line is in more than one crontab; see where cron jobs are stored.
Can I get an alert when a cron job does not run?
Yes. Have the job request a monitoring URL when it finishes. When the request is late, the check alerts you by email, Slack, Telegram or a webhook.
Know the moment a job goes quiet

Create a check, add one curl to the job, and CronMissed alerts you when a ping is late or reports a failure.

Start monitoring