Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm having some periodic issues running a particular application, XBMC. If I use XBMC regularly I don't seem to have any issues but if I leave it unattended for more than about 12 hours I need to reboot to get it working again.

I know a scheduled reboot is NOT the answer but until I can figure out the problem I need to schedule a reboot each morning so my wife can use it if I'm away and it doesn't get thrown out the window :)

Any takers?

share|improve this question

3 Answers 3

up vote 21 down vote accepted

I'd use cron (should already be installed):

Edit crontab:

sudo crontab -e

The first time you might have to choose your preferred editor (like nano)

Insert a line like

0 4   *   *   *    /sbin/shutdown -r +5

at the bottom. Explanation:

m      h    dom        mon   dow       command
minute hour dayOfMonth Month dayOfWeek commandToRun

so the line

  0 4   *   *   *    /sbin/shutdown -r +5

would reboot your system every day at 4:05am. (4:00am + 5 minutes)

Ctrl+X, Y, Enter should get you out of crontab (if using nano)

Note: you might have to run crontab -e as root, because shutdown needs root.

share|improve this answer
    
Suggestion: don't use now, use +5, so that anyone who does happen to be logged in at 4am will get five minutes warning. –  poolie Nov 17 '10 at 21:31
    
Thanks for the info. The only thing I had to do was change the command to /sbin/shutdown to get it to work for me. –  Richard Edwards Nov 18 '10 at 21:17

Adding this to /etc/cron.daily/zz-reboot should work:

#!/bin/sh
shutdown -r now

And sudo chmod a+x /etc/cron.daily/zz-reboot. The "zz" prefix will force it to run last out of all the other scripts in that directory. Check /etc/crontab to see what time of day that will actually happen:

grep daily /etc/crontab | awk '{print $2 ":" $1}'

If that won't work, then a "regular" cron entry can work too, via sudo crontab -e

MINUTE HOUR * * * shutdown -r now

And finally, if you want to just do one-off reboots, you can use at:

echo "shutdown -r now" | sudo at 04:30
share|improve this answer
    
as far as I know this will reboot your system the same time you created this file every day, please correct me if I'm wrong –  sBlatt Nov 17 '10 at 21:22
    
Not quite: it will reboot once per day at whatever time cron.daily runs, which is a bit unpredictable. If you don't have anacron installed, it's 06:25 local time, which might be ok (or might be awful if you're an early riser). If you do, which I think is the default, it could well be 10 minutes after the machine turns on for the first time each day, which would be infuriating. At any rate, cron.daily is not a good fit for this. –  poolie Nov 17 '10 at 21:27
    
cron.daily run every night at 6:25 on my system. This is usually set to a random minute between 06:00 and 06:59. See your /etc/crontab for the time on your system –  elzapp Nov 17 '10 at 21:30
    
The biggest problem with using cron.daily for this is that it might interfere with other jobs in cron.daily. –  elzapp Nov 17 '10 at 21:31

You should create a script using the directions given by Kees Cook...

You can just copy and paste the information below in any text editor and create the zz-reboot file in the directory suggested.

After that just remember to right click on the file and assign it execution permission. If you feel like doing in using terminal just:

sudo chmod +x /etc/cron.daily/zz-reboot

To understand better what you're doing remember that in etc folder you generally find configuration files and there you can find cron.hourly, cron.daily and other cron folders. Cron takes care of executing applications and script at a certain time.

If you want to be strict about the reboot time just digit

sudo crontab -e

so you can edit the croontab for the root user.

If you feel better doing it graphically you can install from the Software Center gnome-schedule. If you want to modify the gnome-schedule for root user ensure that you run it from terminal:

gksudo gnome-schedule

Have fun playing aroud! :)

ps great point sBlatt! I was wondering if there's any way to force cron.daily execution time manually

share|improve this answer
    
In /etc/crontab there is an entry to adjust time, but afaik, if the computer is down at this time, it will execute some minutes after the computer started –  sBlatt Nov 17 '10 at 21:46

Your Answer

 
discard

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