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
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
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.