Troubleshoot and Check Cron Job Logs


cron is a very useful tool and mechanism to schedule jobs in a Linux operating system. cron can run scripts, commands, binaries if set properly. But in some cases, there may be some misconfiguration or unexpected behavior. So we may not be sure whether cron runs as we want. We can check cron log in order to get more detail about the job. By the way, more details about cron can be learned from the following tutorials.

Linux Crontab Syntax and Examples

Linux Crontab Tutorial with Examples To Schedule Jobs

Cron Log Path

cronlogs are stored in a general log file named syslog . This file can be found most of the popular distributions like CentOS, RHEL, Debian, Ubuntu. syslog file is located regular log directory  /var/log/syslog .

$ cat /var/log/syslog
Cron Log Path
Cron Log Path

Check Cron Log Lines

As we can see in the previous example there are a lot of log lines which is produced by different Linux component. But we need to find cron logs. There is a to filter and check only cron log lines. Every cron log line contains the string CRON. So we will filter lines containing CRON with grep command like below.

$ grep CRON /var/log/syslog
Check Cron Log Lines
Check Cron Log Lines

As we can see log lines provides following information.

  • Date provides when the log is created.
  • hostname provides the hostname of the system.
  • root the user account which is used to run cron job.
  • CMD what type of thing is trying to run which is the command in this case.
  • and the last part provides the command tried to run.
LEARN MORE  Linux logger Command Usage Tutorial with Examples

Follow Cron Logs In Real Time

If we want to read the cron job logs in real-time we can use the tail command with -f option. This will read the log file and print it to the screen. But before printing, we will filter only CRON lines with grep command like below.

$ tail -f /var/log/syslog | grep CRON

Leave a Comment