How to automatically reboot my server every 4 hours?

10,490

The crontab Method

  • Open your Terminal or SSH into your server
  • Type sudo crontab -e and the press ENTER
  • Use the down arrow key to go to the bottom of the text
  • Type 0 */4 * * * sudo reboot
  • Press CTRL+X
  • Press Y
  • Press ENTER

If all went well, it should reboot every 4 hours, on the hour.

Share:
10,490

Related videos on Youtube

G. Macasero
Author by

G. Macasero

Updated on September 18, 2022

Comments

  • G. Macasero
    G. Macasero over 1 year

    I need help with my dedicated Ubuntu server.
    How can I reboot my server every 4 hours?

    • AnotherKiwiGuy
      AnotherKiwiGuy over 7 years
      Have you thought about cron? Something like 0 */4 * * * sudo reboot?
    • G. Macasero
      G. Macasero over 7 years
      Im just new with ubuntu. but i know about crontab
    • John N
      John N over 7 years
      Why do you need your server rebooted? As ThatGuy mentioned, cron may be a good place to start. But in general Unix and Unix-like machines should be capable of running for days (or even weeks or months!) without needing restarted. It sounds like there may be another issue that needs addressing.
    • G. Macasero
      G. Macasero over 7 years
      Because i'm runnning 8 minecraft servers in my dedicated server.
    • AnotherKiwiGuy
      AnotherKiwiGuy over 7 years
      @JohnN has a point. Even with Minecraft servers, they should not require that the server be rebooted that frequently, unless you've misconfigured the game servers, or use mods with severe memory leaks.
  • Giridhur
    Giridhur over 7 years
    But would it automatically log in to the user account?
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    What user account? It would reboot the server using the root account, which should override every other user, regardless who is logged in.
  • Admin
    Admin over 7 years
    @ThatGuy I think Giridhur is asking if after restart the log-in will be automatic.
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    @tomas - I see. If it is using Ubuntu Server, then definitely not. It would be a potential security problem, no administrator wants their server to auto login. If it's Ubuntu Desktop, then it depends on how he configured it.
  • Admin
    Admin over 7 years
    @ThatGuy I think you should address your reply @ Giridhur.