Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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