On Ubuntu 18.04, man cron says

cron logs its action to the syslog facility 'cron', and logging may be controlled using the standard syslogd(8) facility

Also, the default configuration of cron is controlled by /etc/default/cron which is read by the init.d script that launches the cron daemon. This file determines whether cron will read the system's environment variables and makes it possible to add additional options to the cron program before it is executed, either to config‐ ure its logging or to define how it will treat the files under /etc/cron.d.

I added a job into /etc/crontab

* * * * * t ( date && echo $PATH && date )

I try to look up the output of the job, and why couldn't I find it in syslog? Thanks.

$ less /var/log/syslog
Nov  3 12:21:01 ocean CRON[23992]: (t) CMD (( date && echo $PATH && date ) )
Nov  3 12:21:01 ocean CRON[23985]: (CRON) info (No MTA installed, discarding output)

$ cat  /etc/default/cron
# This file has been deprecated. Please add custom options for cron using
# $ systemctl edit cron.service
# or
# $ systemctl edit --full cron.service

cron logs its actions to syslog, with a level of detail dependent on the configured log level. This doesn’t include jobs’ output.

Regarding the latter, the manpage says

When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists).

Since you don’t have a configured MTA, output is discarded, as indicated in your logs.

If you want to configure an MTA, the MTA packages in Debian and derivatives come with nice installation scripts which can configure a simple setup for you; sudo apt install postfix and follow the prompts.

Alternatively, you can redirect the output of your cron jobs to the system log by using logger: pipe the output of your jobs to logger -p cron.info (for regular output) and logger -p cron.err (for errors).

The reason cron expects to send output by email is that cron jobs’ output has a granularity which doesn’t match the system logger’s (logs aren’t stored per user). Each user of a system can set up cron jobs, but users don’t necessarily have access to the system logs, and they might not want all other users with access to those logs to see their jobs’ output. When cron was designed, email was a sensible way to get the output of a cron job to the user who managed it: it was expected that Unix systems had a working email setup. Nowadays it’s less obvious, not because the suitability of email has changed, but because its availability has. On systems with working email, it still makes sense to use that for cron output; alternatively, jobs can output to per-user log files (with specific redirections in each job).

systemd timers don’t suffer from this issue: user timers log to the private, per-user journal.

  • Thanks. cronie's manpage says" The syslog output will be used instead of mail, when sendmail is not installed." Does Debian's cron not use syslog in the same case? – StackExchange for All Nov 3 '18 at 16:46
  • 1
    Tim indeed quoted this part of the manual, some hours before this question, in unix.stackexchange.com/questions/479517 . – JdeBP Nov 3 '18 at 16:48
  • @Tim the log message describes what cron is doing: it discards the output if no MTA is available. As I mentioned before, you can’t read other systems’ cron documentation and expect it to apply to Debian’s versions (and vice versa). – Stephen Kitt Nov 3 '18 at 17:02
  • Thanks @JdeBP, I didn’t take the time to read all of Tim’s cron questions today before answering this one. – Stephen Kitt Nov 3 '18 at 17:03
  • (1) Is MTA the same thing as sendmail? How shall I configure it? (2) Does cron -s work effectivey the same as I add redirection to the command in my cron job? (3) Since my ubuntu is running cron, how can I run cron -s? – StackExchange for All Nov 3 '18 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.