M HYPE SPLASH
// general

How can I schedule a nightly reboot?

By Emily Wilson

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?

5 Answers

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. crontab -e opens a file in /tmp instead of the actual crontab so that it can check your new crontab for errors. If there are no errors, then your actual crontab will be updated.

7

Adding this to /etc/ should work:

#!/bin/sh
shutdown -r now

And sudo chmod a+x /etc/. 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
4

I have been working with cronjobs for about a month at my work and scheduling poweroff, and reboot. It's very simple. I know this was asked about 5 years ago, but if anyone still has problems, you can use this method and you will be set.

open the terminal (ctrl+T)

sudo nano /etc/crontab

scroll all the way to the bottom and enter the below command

00 6 * * * root reboot 

this is set for reboot at 6am everyday, and press enter

If you want to schedule poweroff at 11pm everyday you can enter

00 23 * * * root poweroff

I still need to figure out how to poweron a machine using cronjob when it's down. I will edit this answer once i figure it out.

P.S. this is my first ever answer posting on any forms; hope it helps someone!! :D

3

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/

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 crontab 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 around! :)

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

1

Consider

0 6 * * * sudo shutdown -r 

This will a 6 am reboot every day. I like this because it allows a 1 minute delay to shut down any other background jobs and warns anyone else that a shutdown is pending.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy