Where is the cron / crontab log store in Linux system?

On most Linux systems, the system-wide cron daemon’s logs are stored in the /var/log directory, usually in a file called cron or cron.log. This file can be rotated, compressed, and managed using the logrotate utility.

User-specific cron logs are not created by default, but you can configure your crontab to redirect output to a file if desired. You can do this by adding a line to your crontab file like this:

* * * * * /path/to/command > /path/to/log 2>&1

This will redirect both the standard output and standard error of the command to the specified log file. You can also specify a different location for the log file for each command in your crontab, if desired.

It is also possible to configure your system to send an email to the owner of the crontab file or to a designated email address for each cron job run. You can do this by adding the following line to your crontab file:

MAILTO=user@example.com

This will cause an email to be sent to the specified address containing the output of the cron job.

Here are a few more details about cron logs on Linux systems:

  • The system-wide cron daemon logs all cron jobs, whether they are executed by the system or by users. This includes the command that was run, the user that ran it, and the time at which it was run.
  • User-specific cron logs are not created by default, but you can configure your crontab to redirect output to a file if desired, as I mentioned earlier.
  • The logrotate utility is used to manage the size and rotation of log files on a Linux system. It is typically configured to rotate log files on a regular basis (e.g. daily, weekly, monthly) and to compress old log files to save space. You can use the logrotate utility to configure the rotation and compression of the cron or cron.log file in the /var/log directory.
  • If you want to view the contents of the cron or cron.log file in real-time as new entries are added, you can use the tail command. For example, you can use the following command to view the last 10 lines of the cron.log file and follow it as new entries are added:
tail -f /var/log/cron.log
  • If you want to search the cron or cron.log file for specific entries, you can use the grep command. For example, you can use the following command to search for all entries containing the string “test” in the cron.log file:
grep "test" /var/log/cron.log

Related Solutions