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 have a backup script that gets executed daily via a cron job. It's copying from FTP servers, and attached USB harddisks, databases and etc.

At the end of the script, I want to reboot the Linux machine, so I put in the end of the script:

reboot

But typing uptime next day reveals that it didn't reboot. The cron job is executed by the root user, so I shouldn't need to put sudo or su infront of the command, afaik. So instead I tried other variants of the command, like:

shutdown -t 10 -r
shutdown -r now
/sbin/shutdown -t 10 -r
/sbin/shutdown -r now
/sbin/reboot

One attempt at a time of course, not all the above 5 lines after each other. The PC just doesn't reboot.

Does anyone have any ideas about this?

share|improve this question

migrated from stackoverflow.com Mar 26 '13 at 13:07

This question came from our site for professional and enthusiast programmers.

    
Is the script executable? –  Remco Haszing Mar 26 '13 at 10:45
2  
check out logs around the time the reboot is supposed to happen. note that the PATH variable is not sourced from the shell config for cron jobs so "shutdown" will not be found. –  Gung Foo Mar 26 '13 at 10:45
    
It's a bash script. And the cron job is called using a path (/home/username/backup.sh), but the individual commands in the script are called without paths, and they all run fine. Only the reboot command refuses to be executed. –  mr_lou Mar 26 '13 at 10:58
2  
Also add logger commands inside your script (to write appropriate messages to the syslog), to check that indeed it has run. Maybe even logger -t $0 reboot is $(which reboot) –  Basile Starynkevitch Mar 26 '13 at 11:12

3 Answers 3

Hell of a way to reboot it is to use

reboot -f

But this will reboot your machine in 3 seconds without gracefully stopping any services\apps, so you might consider another way around.

Also shutdown may not recognize the "-t" argument, taking the time argument like this instead:

shutdown -r 10 //reboot in 10 seconds

Anyways, man shutdown may come in handy.

share|improve this answer

You can use init 6 to reboot the system :) for more abt init check this http://linux.about.com/od/commands/l/blcmdl8_init.htm

share|improve this answer

Allow reboot for user using visudo

your_username ALL= /sbin/reboot

In your script change reboot to sudo reboot

share|improve this answer
    
The script is run as root, how will this make a difference? –  terdon Mar 26 '13 at 13:21

Your Answer

 
discard

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