1

I replaced exec cron with exec cron -L 15 the run sudo service cron reload, sudo service cron restart but nothing changed. Cron doesn't log the end of jobs and doesn't log failed jobs. I hade no problem in Ubuntu 14.04, but now I have this problem in Ubuntu 16.04. What do I do wrong?

Step by Step: First I changed /etc/init/cron.conf:

sudo sed -i 's|exec cron$|exec cron -L15|' /etc/init/cron.conf && sudo restart cron && cat /etc/init/cron.conf

So now it is

$ cat /etc/init/cron.conf
# cron - regular background program processing daemon
#
# cron is a standard UNIX program that runs user-specified programs at
# periodic scheduled times

description "regular background program processing daemon"

start on runlevel [2345]
stop on runlevel [!2345]

expect fork
respawn

exec cron -L 15

I made the same config in my Ubuntu 16.04 as well as on Ubuntu 14.04 on the another PC.

The Cron log in Ubuntu 14.04 is the following:

$  grep CRON /var/log/syslog
Aug 26 16:05:01 y1404 CRON[6825]: (y) CMD (foo # JOB_ID_1)
Aug 26 16:05:01 y1404 CRON[6824]: (CRON) error (grandchild #6825 failed with exit status 127)

So you can see the second line with error notification about nonexistent command foo. But in Ubuntu 16.04 there is no error notification in the log:

Aug 26 16:25:01 my CRON[7259]: (y) CMD (foo # JOB_ID_129)
  • Could you please add a little more detail? What exactly did you do, what did you want to achieve and what happened instead? Did you encounter any warning or error messages? Please reproduce them in their entirety in your question. You can select, copy and paste terminal content and most dialogue messages in Ubuntu. (see How do I ask a good question?) – dessert Aug 26 '17 at 10:19
  • No warnings, but no errors are logged anymore. – max5555 Aug 26 '17 at 13:30
  • That's strange indeed. Did you try other values like -L 4 or -L 5? – dessert Aug 26 '17 at 13:42
  • I tried -L 5 - the result is the same. I tried even -L 0, then sudo service cron reload, sudo service cron restart, but cron keeps to log, so it doesn't read /etc/init/cron.conf at all? – max5555 Aug 26 '17 at 14:00
  • This seems dumb, but did you try a reboot instead? I'm not totally sure what service cron re{load,start} actually do. cron -L 0 is not supposed to log anything, there's something wrong here. – dessert Aug 26 '17 at 14:09
1

From Ubuntu 15.04 on, upstart using /etc/init/*.conf is replaced by systemd using configuration files in /lib/systemd/system/ and /etc/systemd/system/. Although a file /etc/init/cron.conf is still existent in Ubuntu 16.04, the script normally in use to start cron now is /lib/systemd/system/cron.service. If you want to add extra options, edit this file with

sudo systemctl edit --full cron

and replace the line

ExecStart=/usr/sbin/cron -f $EXTRA_OPTS

by e. g.

ExecStart=/usr/sbin/cron -L 15 -f $EXTRA_OPTS

To reload the configuration, run sudo systemctl restart cron or just reboot. You can test what exact command a service was started with using systemctl status, e. g. for cron (see last line):

> systemctl status cron
● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since So 2017-08-27 09:56:18 CEST; 1h 15min ago
     Docs: man:cron(8)
 Main PID: 26021 (cron)
   CGroup: /system.slice/cron.service
           └─26021 /usr/sbin/cron -f
  • 1
    The proper way to edit /lib/systemd/system/cron.service is sudo systemctl edit --full cron. sudo systemctl daemon-reload doesn't work to apply changes. The working way is systemctl restart cron.service or reboot. – max5555 Aug 27 '17 at 16:00
  • I edited it in and now we have good instructions for future use, thank you very much for caring about this! – dessert Aug 27 '17 at 16:17
  • 1
    @SDsolar That sounds reasonable: Upgrading to 16.04 may not change this behaviour, so the old upstart approach applies nevertheless. Thanks for adding this information here! – dessert Oct 21 '17 at 8:43
  • 1
    I decided to make the change in both places. Turns out also that sudo systemctl restart cron works the same as sudo service cron restart in this hybrid situation. You can watch it with wcron if you created it per askubuntu.com/questions/966194/… – SDsolar Oct 22 '17 at 4:43

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.