Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
    
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 '13 at 19:18

You must log in to answer this question.

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