Where do cron logs live?

On this page

Cron logs two different things in two different places. The daemon logs that it started a job, in the system log or the journal. The job's own output goes to mail by default, which is why it so often goes nowhere. Redirect the output to a file you can read.

Where is the record that cron ran a job?

  • On systemd machines: journalctl -u cron or journalctl -u crond, depending on the distribution.
  • On machines with a classic syslog: /var/log/syslog, /var/log/cron or /var/log/cron.log. The cron(8) manual says cron can send messages to syslog with its -s option, and uses syslog for output when mail is not available.
  • A line shows the user and the command at the moment the job started. It does not show how the job ended.

Where does the job's output go?

By default cron mails any output a job produces to the owner of the crontab, or to the address in MAILTO. If MAILTO is empty, nothing is sent. If the machine has no mail system, the output is lost. Send it somewhere you can read:

crontab
15 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

The 2>&1 sends the error stream to the same file. Rotate the file with logrotate so it does not grow without end.

How do I know how a job ended?

Cron does not record the exit status. Have the job do it: write the status to the log, or better, report it. A ping to /<exit status> records it with a time stamp and the end of the output, and an alert goes out if it is not 0.

crontab
15 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1; curl -fsS --retry 5 https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10/$?

Sources

Questions and answers

Why is nothing in /var/log/cron on my server?
Many current distributions log to the journal only. Use journalctl -u cron, or install a syslog daemon if you want the file.
Can I log to the journal from a job?
Yes. Pipe the output through logger, for example command 2>&1 | logger -t backup, and read it with journalctl -t backup.
Know the moment a job goes quiet

Create a check, add one curl to the job, and CronMissed alerts you when a ping is late or reports a failure.

Start monitoring