How To Reboot Raspberry Pi On A Schedule

by Danny
6 comments

READING TIME: 3 MINUTES

Are you looking for the quickest and easiest way to reboot your raspberry pi nightly? If so, look no further than this how-to guide. This simple 1-line command also works with Linux or Ubuntu virtual machines and servers, too, so feel free to schedule reboots daily, nightly, or even

Sure, there a lot of different methods. I spent about an hour testing a few I’ve found in various forums, but after testing this one on 4 of my raspberry pi’s (as well as two Linux VM’s), I can confirm that this seems to be the easiest and most effective method.

Hopefully this helps you schedule reboots without having to scour the web for an answer!

Step By Step: How To Schedule Daily Reboots of your Raspberry Pi

Step 1: Log into your Raspberry Pi.

Log into your raspberry pi with whatever method you choose. (I prefer VNCviewer, but Webmin or SSH is fine too)

Step 2: Open Terminal

Open a terminal and type this command:

sudo crontab -e

If you haven’t edited anything in the crontab before, select your editor.

Press #1 to choose the nano file editor. Then press the down arrow to scroll to the very bottom.

Step 3: Add Scheduled Reboot Time

Enter this command to schedule a reboot. This command will schedule a daily reboot at 6am.

0 6 * * * /sbin/shutdown -r now

If you want to automatically reboot your raspberry pi at a certain interval using minutes and hours (for example, 1:03pm), the command you’d enter would look like this:

03 13 * * * /sbin/shutdown -r now

Use Cases

Why would you need to reboot your raspberry pi daily (or nightly)?

First of all, while raspberry pi’s are powerful, they do tend to max out the total memory fairly quickly. This may make your raspberry pi run a little sluggish over time.

For example, I’m using several raspberry pi dashboards to display a certain URL (in my case, Microsoft Teams channel). I’ve configured my raspberry pi’s to never sleep which may also be a contributing factor in the slowness. For the most part, the latest Teams channel comments show up correctly. However, after a few days I’ve noticed that the webpage seems to just freeze up. Even refreshing the tab doesn’t always fix it. I’m not entirely sure what causes this, but I do know a reboot fixes the problem.

I’ve also configured Duo into my OpenVPN server. A nightly reboot forces our users to re-authenticate with Duo every morning before they connect to the VPN. This seemed like a preferable option rather than settings a reneg-sec option, as our users don’t always connect at the same time and I’d hate to boot users out midday. For us, scheduling a reboot at midnight is a better solution.

Other use cases might be:

  • Restarting OpenVPN server on a schedule
  • Rebooting to refresh application
  • Auto-updating to keep your Rasbperry pi or Linux packages up-to-date

Wrapping Up

Hopefully you found this simple guide helpful! I know it’s not a huge problem to solve, but hopefully this saves you from needing to test out a few different solutions.


My Homelab Equipment

Here is some of the gear I use in my Homelab. I highly recommend each of them.

The full list of server components I use can be found on my Equipment List page.

6 comments

You may also like

6 comments

Erotik Izle December 9, 2020 - 12:07 pm

Thanks for sharing, this was very useful!

Reply
Flicho May 13, 2021 - 7:57 pm

/sbin/shutdown -r now ?!?
/sbin/reboot 😉

Reply
tito August 25, 2021 - 1:11 am

works on /sbin/reboot

Reply
John June 10, 2021 - 2:54 pm

How do I save it? When pressing Ctrl+O it just saves a temporary file

Reply
Jade July 10, 2021 - 1:36 am

Assuming you are using nano as your text editor.

I use, Ctrl+s, to save the file.
Then Ctrl+x, to close the file.

Alternatively, I believe you can also just use Ctrl+x, then press ” y ” to say yes to saving the file.

Reply
Danny July 11, 2021 - 5:29 am

I totally forgot to add that to my post – thank you. I will be adding that to the guide thanks to you.

Reply

Leave a Comment