Hosting and DomainServers

How to Restart the Linux Server Every Midnight: A Step-by-Step Guide

At some point, you may need to restart your Linux server regularly for various reasons. For instance, you may want to ensure that the system runs smoothly and efficiently by refreshing the memory, closing unused applications, and releasing system resources. Restarting your server regularly also helps to apply updates and patches, which is critical to maintaining the security and stability of your system.

In this guide, we will show you how to restart your Linux server every midnight automatically. This process will ensure that your server stays up to date and performs at its best. The steps outlined in this guide are specific to Ubuntu and other Debian-based distributions.

Step 1: Install the cronjob utility

Cron is a time-based job scheduler in Unix-like operating systems. It enables users to schedule and automate tasks at specific intervals. To install the cronjob utility, open the terminal and type the following command:

sudo apt-get install cron

Enter your password when prompted, and the cronjob utility will be installed on your system.

Step 2: Create a new cronjob

To create a new cronjob, you need to edit the crontab file. Open the terminal and type the following command to open the crontab file:

sudo crontab -e

This command will open the crontab file in the default text editor. Scroll down to the bottom of the file and add the following line:

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

This line specifies the time and command that you want to run. In this case, the server will restart at midnight (0 0 * * *) every day using the shutdown command with the -r (restart) option.

Save the file and exit the editor. Your new cronjob is now set up and will automatically restart your server every midnight.

Step 3: Verify that the cronjob is running

To verify that the cronjob is running, you can check the system logs. Open the terminal and type the following command:

sudo grep CRON /var/log/syslog

This command will display the cron logs for the current day. You should see a log entry for the cronjob that you created, indicating that it ran successfully.


In this guide, we showed you how to restart your Linux server every midnight automatically using the cronjob utility. By automating this process, you can ensure that your server stays up to date and performs at its best. Remember to test your cronjob to make sure that it works correctly and to adjust the timing if necessary.

If you have any questions or concerns about this guide, feel free to contact us. We are always here to help you.

Related posts
Hosting and Domain

We Compared the Top Web Hosting Services of 2023: Here's Our Verdict

Are you looking for a reliable web hosting service that meets your website’s needs and budget?
Read more
Hosting and Domain

Hostinger vs HostGator vs Bluehost: A Comprehensive Review of the Best Web Hosting Services in 2023

Choosing the right web hosting service can be a daunting task. There are countless providers to…
Read more
Hosting and Domain

How to Exit from Rescue Mode in Linode

To exit from rescue mode in Linode, follow these steps: Boot your Linode into rescue mode by…
Read more
Become a Trendsetter

Sign up for KDJ Guru's Daily Digest and get the best of KDJ Guru Articles, tailored for you.

Leave a Reply

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