schedule reboot linux

How to Schedule Reboot in Linux

System reboot allows you to reset all processes & tasks running on it, remove temporary files and free up memory. It allows you to improve system performance and reduce server loads. It is a good practice to regularly reboot your system. However, it can be tedious to remember when to reboot and manually do it every time. So it is advisable to schedule reboot to be run at regular intervals on your system. You can do this easily in Linux. In this article, we will look at how to schedule reboot in Linux.


How to Schedule Reboot in Linux

Crontab is the most commonly used to create cron jobs that run processes, scripts & commands at scheduled time. We will use it to schedule system reboot for us. Crontab consists of cronjobs specified by user. Each cronjobs is a command or script or process along with the times when they are supposed to be executed. The cron daemon regularly goes through the crontab document and runs the cronjobs up for execution.

Open terminal and run the following command to open crontab.

$ crontab -e

It will open the crontab in a text editor.

Add the following command on a separate line in the file.

00 10 * * * shutdown -r

Save and close the file. Now you have scheduled a reboot at 10.a.m daily according to the system’s timezone.

Let us look at the above line in detail. The format of each cronjob in crontab file is the following.

minute hour day_of_month month day_of_week command_to_execute

In our cronjob, we have used ’00 10 * * *’ to run the cronjobs every day at 10.a.m. The command to be executed is ‘sudo shutrown -r’ which basically reboots the system.

You can use an online cronjob generator to easily generate cronjob command as per your requirement.

Now let us look at cronjob commands for some common use cases.


Reboot Every Night

Here is the cronjob command to restart system every night at 10.p.m

00 22 * * * shutdown -r


Reboot Weekly

If you want to reboot your system every Sunday night at 9.p.m. then here is the cronjob syntax for it.

00 21 * * Sun shutdown -r
OR
00 21 * * 0 shutdown -r
OR
00 21 * * 7 shutdown -r

That’s it. In this article, we have learnt how to schedule reboot at different times. If you don’t want to reboot but only shutdown then remove -r option from above commands.

Also read:

How to Redirect Nohup output to File
How to Install Dependencies with Apt
How to Install Dpkg Dependencies Automatically
How to Disable Unnecessary Services in Linux
Top SFTP Command Examples

2 thoughts on “How to Schedule Reboot in Linux

    • Thank you very much for pointing it out. We have removed sudo from the commands. But only users with shutdown privileges will be able to run the command.

Leave a Reply

Your email address will not be published. Required fields are marked *