Question

How to check if cron is working on Ubuntu 20.04?

Posted May 18, 2021 738 views
Ubuntu 20.04

I am trying to test a cron job.

When I run crontab -l the output is:

*/1 * * * * curl https://www.google.com >> /home/log/crontest.log 2>&1

I also have the following to set cron log in the /etc/rsyslog.d/50-default.conf:

cron.*  /var/log/cron.log

And created a file /var/log/cron.log and /home/log/crontest.log.

I restarted the system, sudo service rsyslog restart.

But nothing is logged.

Q1. Is there any way that I can test if the corn is working?
Q2. What could be the reasons that the cronjob is not working?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hello, @okadashinichi2819

You can manually execute the cron job command in your shell and check for any errors. If the cron is executed fine then it should work when configured to run at specific times.

You can also check our tutorial on how to setup cron jobs:

https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-ubuntu-1804

You can also use sites like this one to generate the exact time format for you:

https://crontab-generator.org/

Regards,
Alex

by Mark Drake
Cron is a time-based job scheduling daemon found in Unix-like operating systems, including Linux distributions. This guide provides an overview of how to schedule tasks using cron's special syntax on a machine running Ubuntu 18.04. It also goes over a few shortcuts one can use to make job schedules easier to write and understand.

Hello you can also view content of /var/log/syslog to watch crons and see if they are coming at the correct time.

  • I have a bunch of suspended and resumed.

    ...
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' resumed (module 'builtin:omfile') [v8.2001.0 try https://www.rsyslog.com/e/2359 ]
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' suspended (module 'builtin:omfile'), retry 0. There should be messages before this one giving the reason for suspension. [v8.2001.0 try https://www.rsyslog.com/e/2007 ]
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' resumed (module 'builtin:omfile') [v8.2001.0 try https://www.rsyslog.com/e/2359 ]
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' suspended (module 'builtin:omfile'), retry 0. There should be messages before this one giving the reason for suspension. [v8.2001.0 try https://www.rsyslog.com/e/2007 ]
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' resumed (module 'builtin:omfile') [v8.2001.0 try https://www.rsyslog.com/e/2359 ]
    ...
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' resumed (module 'builtin:omfile') [v8.2001.0 try https://www.rsyslog.com/e/2359 ]
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' suspended (module 'builtin:omfile'), retry 0. There should be messages before this one giving the reason for suspension. [v8.2001.0 try https://www.rsyslog.com/e/2007 ]
    May 20 00:45:01 sendy-email-client rsyslogd: action 'action-4-builtin:omfile' suspended (module 'builtin:omfile'), next retry is Thu May 20 00:45:31 2021, retry nbr 0. There should be messages before this one giving the reason for suspension. [v8.2001.0 try https://www.rsyslog.com/e/2007 ]
    May 20 00:45:05 sendy-email-client systemd[1]: Created slice User Slice of UID 1000.
    May 20 00:45:05 sendy-email-client systemd[1]: Starting User Runtime Directory /run/user/1000...
    May 20 00:45:05 sendy-email-client systemd[1]: Finished User Runtime Directory /run/user/1000.
    May 20 00:45:05 sendy-email-client systemd[1]: Starting User Manager for UID 1000...
    May 20 00:45:05 sendy-email-client systemd[22789]: Reached target Paths.
    May 20 00:45:05 sendy-email-client systemd[22789]: Reached target Timers.
    May 20 00:45:05 sendy-email-client systemd[22789]: Starting D-Bus User Message Bus Socket.
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on GnuPG network certificate management daemon.
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers).
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on GnuPG cryptographic agent and passphrase cache.
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on debconf communication socket.
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on REST API socket for snapd user session agent.
    May 20 00:45:05 sendy-email-client systemd[22789]: Listening on D-Bus User Message Bus Socket.
    May 20 00:45:05 sendy-email-client systemd[22789]: Reached target Sockets.
    May 20 00:45:05 sendy-email-client systemd[22789]: Reached target Basic System.
    May 20 00:45:05 sendy-email-client systemd[1]: Started User Manager for UID 1000.
    May 20 00:45:05 sendy-email-client systemd[1]: Started Session 2652 of user shin.
    May 20 00:45:05 sendy-email-client systemd[22789]: Reached target Main User Target.
    May 20 00:45:05 sendy-email-client systemd[22789]: Startup finished in 116ms.
    

    I have a cron-job NOT working. Is it related to this suspended log?