Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying execute a basic shutdown crontab to run M-F at 10PM. So I did the following:

sudo crontab -e

Once inside of the crontab I added the following line:

0 22 * * 1-5 shutdown now

The job doesn't seem to be running properly and I cannot find any errors in /var/log/syslog. Is there anything glaringly wrong here?

share|improve this question

4 Answers 4

up vote 6 down vote accepted

Your problem is probably that the PATH in your crontab file is limited and does not include /sbin where shutdown is most likely located.

You should therefore use the full path for shutdown (you can check that with sudo which shutdown ):

0 22 * * 1-5 /sbin/shutdown now

From man 5 crontab:

Note in particular that if you want a PATH other than "/usr/bin:/bin", you will need to set it in the crontab file.

Instead of specifying the /sbin/shutdown you could do:

PATH = /sbin:$PATH
0 22 * * 1-5 shutdown now
share|improve this answer
    
This was the fix! Thanks so much! –  inquisitor Jun 26 '13 at 15:47

Check tail -n 100 /var/log/cron

And are you trying to run this cron using normal or root user?

share|improve this answer
    
I don't have that directory. –  inquisitor Jun 26 '13 at 14:56
    
Trying to run it as root –  inquisitor Jun 26 '13 at 14:58
    
Ok, try sudo grep -ic cron /var/log/* | grep -v “:0” . And what about the crond service?? –  OmiPenguin Jun 26 '13 at 15:00
    
grep finds it in my auth.log, pm-powersave.log, and syslog. I checked those files and none of the information given on cron was helpful –  inquisitor Jun 26 '13 at 15:02
  1. You can try to list the execution times with cronlist to see if it will run when you expect. As far as I can tell the cron job will be run at 22:00 Monday through Friday; is that what you want?
  2. What does shutdown now print if you execute it as a normal user?
  3. What does service cron status print? If it doesn't say cron start/running, you'll have to restart it with service cron start.
  4. Is the clock on the machine correct? It could be unconfigured or so out of sync that the job is run at completely the wrong days or time.
  5. Do you have any error messages like PAM bad jump in stack in /var/log/auth.log? That post contains a bunch of debugging information and things to try.
share|improve this answer
    
1.) The cronlist command isn't found on my machine 2.) shutdown: Need to be root 3.) cron start/running, process 1200 –  inquisitor Jun 26 '13 at 15:06
    
Thanks, but this machine isn't connected to the Internet. There must be something silly happening... –  inquisitor Jun 26 '13 at 15:10
    
4.) The time is correct as well. I upvoted you to thank you for helping as these are good troubleshooting steps to take. Ill be sure to post the solution when I find it. It's a baseline ubuntu install and all I'm doing is what is in my post above –  inquisitor Jun 26 '13 at 15:20
    
@nkon I feel your pain. My own non-working crontab is still not fixed, and tomorrow is my last day with that hardware. If you find a solution, it could be related to my problem as well (even though I do get log output). –  l0b0 Jun 26 '13 at 15:21

You do not have access to the shutdown command. Try this executing this:

sudo chmod u+s /sbin/shutdown

then in your crontab, specify the full path to shutdown

0 22 * * 1-5 /sbin/shutdown now
share|improve this answer

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.