How to Check if Crontab is Working?

The crontab is the abbreviation of “cron table” that manages the background tasks/jobs based on “Hours”, “Daily”, “Weekly”, “Monthly”, and “Yearly”. It executes the tasks/jobs in the specified period that is already scheduled. It has various uses for scheduling emails, system backup, and many more.

This article will provide various methods to check the services of crontab in Linux. The content of this article is mentioned below:

Let’s start the article with the service checking method first:

Method 1: Checking the Crontab Service Status

The scheduled jobs are not executed when the cron services are inactive. The service status can also be checked using the “systemctl” utility. To check the status of cron services, follow the below script:

$ sudo service cron status

The output shows that “crontab” services are running.

Method 2: Using the “ps aux” Command to Check Crontab Services

The “ps aux” command monitors the active or running process in the system. The “grep” command searches the pattern/file “cron”. It extracts the process information regarding “cron” services as below:

$ ps aux | grep cron

The output shows that “cron” services are working fine.

Method 3: Using “pgrep” Command to Check Crontab Process ID

The “pgrep” command is utilized to find the process id of the running process. If this command successfully returns the process id means particular services work fine; otherwise, they do not. To check the crontab services, execute the below script:

$ pgrep cron

The output returns the process id “798”, which represents that crontab is working fine.

Method 4: Using Log Files to Check the Crontab Configuration File

To check out the existence of the “crontab” log file, the nano editor assists in this regard. To do so, follow the below script:

$ sudo nano /etc/crontab

The output opens the “crontab” configuration file.

Method 5: Using the “tail” Command to Check the Crontab Services

The “tail” command displays the input file’s last lines. To check the “crontab” configuration file, specify the path directory as below:

$ tail -f /var/log/syslog | grep "cron"

The output returns the last data of the specified “cron” file.

That is all for checking the crontab services.

Conclusion

To check crontab services, “status” utility, “ps aux”, “pgrep”, and “tail” commands are used. These command line utilities provide information on the operating system’s active/dead-running processes. This guide has explained various methods to check the working of crontab services in the system.