4

I'm trying to shutdwon my pc at 2 am once a week.

If I use the user crontab of root (sudo crontab -e)

30 2 * * 3 shutdown -h now

the shutdown will not be performed.

However, if I place the same command for the root in the system-wide crontab (sudo vim /etc/crontab) the pc will shut down:

30 2    * * 3   root    shutdown -h now

What's the difference? Both times root is going to shutdown my pc. Why does it only work if it is in the system-wide crontab?

1 Answer 1

4

In theory either should work. I think you will find the difference is in the PATH. Your version may differ, but in my /etc/crontab there is a PATH line at the top which includes /sbin in it (and my shutdown is in /sbin).

I think you will find that when CRON is executed for the root user it does not have a path associated with it, so it is not working. Change the command to

30 2    * * 3   root    /sbin/shutdown -h now

And I suspect that will solve your problem.

1
  • Works! Just came back from my reboot... Must be the /sbin/-part that was missing. Note that in the user-crontab for root, the user field is not specified. I.e., the line reads: 30 2 * * 3 /sbin/shutdown -h now
    – Philippe
    Feb 1, 2013 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .