Link to home
Start Free TrialLog in
Avatar of gerrymac1943
gerrymac1943Flag for Afghanistan

asked on

cron job every day to reboot at 04:00?

Experts,

I want to use cron to reboot at 04:00am, every morning for my linux ubuntu pc.

Can some one confirm how you would do this using cron?

Cheers
GMac
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Issue command

sudo crontab -e

Then modify

0 4 * * *  /sbin/init 6

Save and exit
Avatar of gerrymac1943

ASKER

i've tested both suggestions separately and they don't work....

0 4 * * *  /sbin/init 6

&

0 4 * * * shutdown -r now

Note to test I reset time using date -s 03:59, but the linux pc did not reboot when it reached 04:00
After resetting the time you'll have to restart the cron daemon, afaik, to make the new time known to ut.

wmp
Make sure the cron daemon is running.  If it is up and running, it should read the time without restarting.

check:
ps -ef | grep cron

Also check the /var/spool/cron*/* directory:

cat /var/spool/cron*/*
Avatar of xterm
xterm

You'll need to set a user to run as, and a full path to the shutdown command, so:
0 4 * * * root /sbin/shutdown -r now

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can make it run as root if you are either:

issue this command as root
crontab -e

Or
sudo crontab -e -u root

That would make the above commands work.
i have followed the following procedure using the commands:

1. opened crontab as root
fcrontab -e

2. entered reboot command which allow reboot at 04:00 every day.
0 4 * * * shutdown -r now

( and also 0 4 * * *  /sbin/init 6)

3. set date to 03:59 to test reboot
date -s 03:59

4. restarted crontab
/etc/init.d/cron restart

However the linux ubuntu pc still does not reboot at 04:00
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
xterm it seems to work @ 4pm thanks when i checked the log file!

Nov  8 04:00:00 ubuntu fcron[1969]: SIGTERM signal received