How do I schedule a reboot on Linux?

75,525

Solution 1

If it is one-time deal, you can use shutdown command with -r as argument. Instead of using shutdown now, you can add time as parameter (e.g. shutdown -r 12:30).

Solution 2

According to the man page: /sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message] found at --> http://unixhelp.ed.ac.uk/CGI/man-cgi?shutdown+8

Load of options to choose from but, to answer your question.

To reboot in 5 minutes: /sbin/shutdown -r 5 "reboot in five minutes"

To reboot at exactly 11:00 P.M.: /sbin/shutdown -r 23:00 "rebooting at 11:00 P.M."

NOTE: your message will be broadcast to all active terminals / sessions.

Solution 3

the at command is what you want.

at 5:00pm 
do
cd /
/full/path/to/init 6
done

at -l will list the at cmds

Solution 4

The easiest way I can think of is:

# sleep 2h && reboot

Run this as root.

Solution 5

echo "reboot" | at -m 23:00       

....

Share:
75,525
jldugger
Author by

jldugger

DevOps Engineer

Updated on September 17, 2022

Comments

  • jldugger
    jldugger over 1 year

    I'd like to be able to schedule a server reboot at a specific time, but not regularly. How can I do this without futzing with adding and removing cron entries?

  • Kamrul
    Kamrul over 14 years
    For rebooting the -r flag is needed (e.g. shutdown -r 12:30)
  • egorgry
    egorgry over 14 years
    -r is critical otherwise you will be hitting a power button somewhere to bring it back up.
  • Dennis Williamson
    Dennis Williamson over 14 years
    I would use shutdown instead of init. It's not necessary to do the cd or the do/done (which would probably produce an error).
  • egorgry
    egorgry over 14 years
    really? I've used this for over 8 years and I've never has an issue. hpux. solaris, linux 2.2 - 2.6
  • warren
    warren over 14 years
    I personally prefer init 6 myself; had intermittent issues with shutdown -r on some platforms in the past
  • Josip Medved
    Josip Medved over 14 years
    This is true, I forgot -r in initial answer. :( sorry.
  • Andrew
    Andrew over 14 years
    This also works with times in the early morning - so if it's 15:55 now, you can use 'shutdown -r 03:15 &' to reboot the server at 3:15am tomorrow morning. (the '&' shunts the command the background so you can log-off without killing the shutdown command)
  • first6684
    first6684 over 9 years
    This has the advantage/drawback (depending on your use case) of alerting everyone every hour or so via a broadcast message of the upcoming reboot.
  • Tebe
    Tebe over 6 years
    what's about root permissinos?
  • Omry
    Omry over 6 years
    as I said, run it as root.