33

When I schedule a job, some seem to be applied immediately, while others after a reboot. So is it recommended to restart cron (crond) after adding a new cron job? How to do that properly (esp. in a Debian system), and should that be done with sudo (like sudo service cron restart) even for that of normal users'?

I tried:

/etc/init.d/cron restart

which doesn't seem to work (neither does /etc/init.d/cron stop or service cron stop) and completes with return code 1.

Here's a part of the message output:

Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the stop(8) utility, e.g. stop cron stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.91" (uid=1000 pid=3647 comm="stop cron ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")

(what does that mean?)

25

No you don't have to restart cron, it will notice the changes to your crontab files (either /etc/crontab or a users crontab file).

At the top of your /etc/crontab you probably have (if you have the Vixie implementation of cron that IIRC is the one on Debian):

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

The reason you might not see specific changes implemented is if you add things to e.g. /etc/cron.daily and the daily run has already occurred.

The message that you get is because you use an old way of restarting cron on your system. The recommended way (but not necessary if you just edit cron files) is:

 restart cron

You of course have to reboot in order to see the effects of a @reboot cron job

7
  • it wasn't a reboot job but every n minutes cron job.. and restarting seems to work with sudo with both the old and new ways.. but not for a normal user..
    – precise
    Jan 30 '14 at 9:01
  • How do you edit the crontab? As user with crontab -e?
    – Timo
    Jan 30 '14 at 9:04
  • yes.. crontab -e is what I use..
    – precise
    Jan 30 '14 at 9:06
  • Do you have Vixie Cron ( look at man cron -> Name)
    – Timo
    Jan 30 '14 at 9:08
  • 1
    It appears that just saving the changes is not enough, and the scheduled jobs apply only after the text editor (I use nano) is closed too! ..and maybe that's caused the confusion...
    – precise
    Jan 30 '14 at 12:19
4

A restart might not be necessary. Like I said in my comments the text-editor that you've used (the one that is assigned for editing cron-jobs) to edit the task needs to be closed; just saving the contents is not enough. (That's what I've experienced. Editing tasks via nano and saving with Ctrl+O with file still open doesn't apply the edits immediately, but only after the editor is closed with Ctrl+X.)

And like mentioned in this answer (by terdon) the cron daemon would check, every minute, to see if any job is to be run and trigger those which it has to.

1
  • I had my crontab file as a symlink to another place and edited the file using vim and saved and closed, still the crons didn't start running, until I opened it using crontab -e and made an unnecessary change to trigger the need to save and saved and exited.
    – faham
    Apr 10 '20 at 15:00

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.