We will discuss in this article how a user can view the cron logs files in a Linux environment. We have performed all tasks on the Ubuntu 20.04 system that will give you a better understanding of the cron logs.
Open the terminal by pressing the keyboard shortcut ‘Ctrl+Alt+t’. Now, using the following two different methods can easily access the cron log events:
Method 1: Check cron logs events through syslog
It is a very simple and easy way to check that cron log events are running on your system. Login as root user on the terminal and type the following command:
The following cron logs events should display on the terminal:
Method 2: Monitor cron logs by setting up the cron.log file
The recommended way is to create a separate ‘cron.log’ file to monitor or check the cron logs events on your Linux system. For this purpose, access the ‘/etc/rsyslog.d/50-default.conf’ file by running the below-given command:
Search the ‘ #cron.* /var/log/cron.log’ in this file and uncomment this line which is also shown in the following screenshot:
Now, create a ‘cron.log’ by using any source code or text editor.
Restart the rsyslog service and then check the running status of this service on your system through the following command:
$ sudo systemctl status rsyslog
The following output should print on the terminal window:
Now, all cron log events to be saved in the cron.log file.
To view, the real-time cron logs events using the ‘watchcron’ command. So, create a ‘watchcron’ file as follows:
Add the following lines in this file:
watch -n 10 tail -n 25 /var/log/cron.log
Save this file in nano using ‘Ctrl+o’ and then press ‘Ctrl+x’ to exit from this environment.
Here, the above watchcron refreshes the logs event page after 10 seconds and displays the last 25 events on the page.
Set the executable permissions on this file by using the following command:
Copy this file in ‘/usr/sbin’ location as follows:
Now, to check the real-time cron logs events run the below-given command on the terminal:
The following window will show on the terminal:
We have explained In this article how you can check or monitor cron logs events in real-time by using a single ‘watchcron’ command.