How to Find cron / crontab log in Linux?

The cron and crontab log is used to keep a record of the activities of the cron daemon on Unix operating systems. The cron or the crontab log, both are known as the cron log. The cron log is located in different directories in different Linux distributions. 

In this post, first, we will dig into the importance of the cron log and then find the methods by which it can be found on UNIX distributions. 

What is the Cron or the Crontab log?

When it is supposed to schedule the activities including the execution of the commands, then cron is used. Therefore, cron is also known as the tie scheduler and it is also used to run the programming scripts after specified intervals of time.

Now this crontab log is important for Unix users because, with it, they can monitor the performance of the executed activities. One can also fix problems that arose while the tasks were being carried out.

This crontab log provides its users with the below-mentioned information:

Job OutputIt displays the standard output which is the combination of the error and outcome of the executed job
Timestamp The time and date when the job is executed using the cron daemon
Status The status of the executed job is displayed which is either failure or success
Error MessagesIf any error or warning messages occurred, they are shown in the error messages
Details The summarized details of the cron daemon activities will be displayed

How to Check Cron Logs in Linux?

To check the cron logs in Linux, two different approaches can be used:

  1. Using the syslog File
  2. Using the cron.log File

Method 1: Check Cron Logs Using the syslog File

The first recommended method of finding the cron log is by using the syslog file. The syslog, an acronym of the System Logging Protocol is used to place the log of all the system’s activities in one place. 

To extract the cron log from it, use the grep command:

$ cat /var/log/syslog | grep cron

The output displays the currently running cron daemon’s activities in the computer. 

Method 2: Check the cron log Using the cron.log File

Another method to check the cron log is by creating a file with the name cron.log. This file will save the cron daemon’s activities. The steps listed below can be used can be use this way to check the cron log.

Step 1: Open the Default cron log File

To open the cron log file, use the text editor. It is suggested that use the nano text editor for opening the default cron log file:

$ sudo nano /etc/rsyslog.d/50-default.conf

Now locate the “#cron.*” in the file and remove the “#” as shown below to uncomment it:

Step 2: Create a cron.log File

Either use the source code or a text editor for the creation of the “cron.log” File:

$ sudo nano /var/log/cron.log

Step 3: Restart the rsyslog Service

Using the systemctl command, restart the rsyslog service:

$ sudo systemctl restart rsyslog

Display the status of the rsyslog to verify its running status:

$ sudo systemctl status rsyslog

Step 4: Check the Real-Time Cron Logs

To check the real-time cron log activity, use the watch command and to do so, first, create a new file and write the bash script to define the watch command with its parameters:

$ sudo nano watchcron

Copy and paste the below script:

#!/bin/bash
watch -n 15 tail -n 30 /var/log/cron.log

To execute the watch command, make the newly created file executable:

$ sudo chmod +x watchcron

Now before running the command, copy the executable file to the /usr/sbin/ with the cp command:

$ sudo cp watchcron /usr/sbin

Finally, execute the watch command to display the real-time activity of the cron log:

$ ./watchcron

On the screen, the real-time cron log activity is visible.

How to Locate the cron or crontab log on Unix Distributions?

To locate the cron and crontab log on different UNIX distributions, run the mentioned commands according to the UNIX distribution.

Install on Ubuntu/Debian

Run the command on Debian-based Linux distributions:

$ grep CRON /var/log/syslog

Install on CentOS/RHEL

Execute the below-mentioned command in CentOS/RHEL:

$ less /var/log/cron

Install on macOS

In the macOS, find the cron log using the command:

log show --predicate 'subsystem == "com.apple.schedule"' --info

Install on Other UNIX Distros

To locate the cron log on other UNIX Distros, use the command:

$ grep CRON /var/log/syslog

This is all about the cron or the crontab log in UNIX operating systems. 

Conclusion

To find the cron or the crontab log in the UNIX operating system, use the command “grep CRON /var/log/syslog” command-line interface. It is used to display the log activity of the Cron Daemon. This post explained the methods by which the cron log can be found on UNIX distributions.