How do I schedule a timed reboot of my server in seconds?

21,248

Try

 sleep 5 ; reboot

on your terminal (as root). If you want it in the background, try

 ( sleep 5 ; reboot ) & 

See also shutdown(8)

Share:
21,248
Dave
Author by

Dave

Updated on August 05, 2022

Comments

  • Dave
    Dave almost 2 years

    I’m using bash shell on Linux …

    $ uname -a
    Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
    

    although it would be nice if I could come up with a solution in any bash supported environment. My question is, in my script I want to scheduled a delayed reboot of my server in 5 seconds. So far, I have the below, but it takes 60 seconds …

    # Timed reboot of server
    sudo shutdown -r 1
    
    # Fail if any of the sub-deployments failed.
    if [[ ( $PROC1_STATUS -ne 0 ) ||
          ( $PROC2_STATUS -ne 0 ) ||
          ( $PROC3_STATUS -ne 0 ) ]]
    then
            exit 1;
    fi
    

    Does anyone know how I can adjust the above except make the timed reboot in 5 seconds instead of a minute? The solution doesn't have to use "shutdown" but it was the only tool I could find.

    • Dave
  • Dave
    Dave over 10 years
    Hi, This seems close but the statements after the "reboot" line don't seem to be getting executed because the system sleeps, the reboot happens and then execution stops.
  • Niklas Holm
    Niklas Holm about 5 years
    Another variant: nohup sudo -b bash -c 'sleep 5; reboot' &>/dev/null; <other commands>