Categories
Linux

How to check if a cron job ran

After a cron job is created or added by a software package such Debian, it is better to double-check if the cron job is actually scheduled and ran. Because cron is a daemon to execute scheduled commands, you will need to check the log output.

Where is the cron log?

Unlike most other software, cron does not come with its own log files. This might be due to cron is so integrated with the operating system: almost all Linux distributions, like Debian, Ubuntu or Linux Mint have cron installed out of box.

Because cron is deemed as part of your operating system, you can check the status of cron jobs in the system log file syslog file located in the /var/log/ directory: /var/log/syslog. This applies to any debian distributions, such Ubuntu or Raspbian on Raspberry Pi.

Search if a cron job has started

By default, cron will only log the start of all jobs, according to its man page.

To search if a cron job, e.g., certbot, has been ran, use grep with the -i option:

grep -i certbot /var/log/syslog

-i makes the pattern you search for case insensitive.

Alternatively, you can also use ag, which is “The Silver Searcher. Like ack, but faster.”:

ag certbot /var/log/syslog

Note that you don’t need to specify the -i option, because ag is case-insensitive by default. So “Certbot” and “certbot” are treated the same.

Unlike grep which does not allow you to search a directory, you can use ag to do that. This way, you can search for any cron job status by running ag JOB_NAME /var/log/. This way you can search for anything without knowing the specific file but only the directory.

What shows a cron job has run?

If the job has been started, the output will look like this and the job name is in bold:

Apr 23 00:00:01 rpi CRON[20088]: (root) CMD (test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Apr 23 01:44:06 rpi systemd[1]: Starting Certbot…
Apr 23 01:44:08 rpi systemd[1]: certbot.service: Succeeded.
Apr 23 01:44:08 rpi systemd[1]: Started Certbot.
Apr 23 12:00:01 rpi CRON[11399]: (root) CMD (test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)

As you can see in the middle 3 lines, we have:

  • Starting Certbot…
  • certbot.service: Succeeded.
  • Started Certbot.

This indicated that the cron job Certbot has been successfully ran. Congrats!

If the output is empty, you cron job has not been run. Unfortuantelly, you will need to investigate into it. Good luck!

In A Nutshell

How to check if a cron job has started

  1. Open a terminal

  2. Use grep to search for the job name, e.g., certbot

    grep -i certbot /var/log/syslog

  3. Check if the output has lines indicate success

    The output should contain those 3 sentences: Starting Certbot… certbot.service: Succeeded. Started Certbot.

Tools
  • Terminal
  • grep

+1

By VarHowto Editor

Welcome to VarHowto!