Ways to Check Whether cron Is Working on Linux
Cron is a time-based job scheduler in Linux which automatically runs scheduled jobs or commands at a specific time interval. This utility is used to automate routine tasks and is an essential tool for system administrators. However, sometimes you may face some issues where cron is not working properly, and the scheduled jobs fail to run. In this article, we will discuss some ways to check whether cron is working on Linux.
1. Check the cron service status:
The first step to checking cron’s status is to ensure that the cron service is running. In most Linux distributions, you can check cron’s service status using the systemctl, service, or chkconfig commands depending on your distribution.
To check the cron service status using systemctl, run the following command:
$ systemctl status cron
To check the cron service status using service, run the following command:
$ service cron status
To check the cron service status using chkconfig, run the following command:
$ chkconfig –list cron
2. Check the cron logs:
Cron logs all its activities in the /var/log/cron file. By examining the log file, you can determine whether cron is working correctly or not. To check the cron logs, you can use the tail command as follows:
$ tail -f /var/log/cron
This command will display the last few lines of the cron log file. You can also use the grep command to search for specific information in the log file. For example, to search for all failed cron jobs, you can use the following command:
$ grep “cron.*CMDFAILED” /var/log/cron
3. Check the cron schedule:
Another way to check whether cron is working correctly is to verify the scheduled jobs. You can view the scheduled cron jobs using the crontab command. To view the current user’s cron jobs, run the following command:
$ crontab -l
This command will display the scheduling table in the standard output. You can also use the vim or nano editor to view and edit the cron scheduling table.
4. Check the email notifications:
Cron sends an email notification to the defined email address after running a scheduled job. You can check the email notifications to ensure cron is working correctly. You can configure the cron email notifications by setting the MAILTO variable in the crontab file. To view the email notifications, run the following command:
$ tail -f /var/mail/$USER
This command will display the last few lines of your mailbox. You can also use the mail command to read the email notifications.
In conclusion, Cron is a powerful tool to automate routine tasks. However, it is important to check whether it is working correctly to avoid any potential issues. By using the methods described above, you can check whether cron is working on Linux and troubleshoot any issues.