Setup ubuntu to reboot automatically at a scheduled time

In the blog below, we have configured to reboot our Ubuntu server to reboot every day at 2 AM Dubai time

 · 2 min read

To set up your Ubuntu server to reboot every day at 2 AM Dubai time, you can use cron, the built-in scheduler in Linux. Here are the steps:

1. Convert Dubai Time (GMT +4) to UTC

Since Dubai time is 4 hours ahead of UTC, you need to schedule the reboot for 10 PM UTC (2 AM Dubai time) because Ubuntu uses UTC for cron jobs by default.

2. Open the Cron Editor

Run the following command to open the cron jobs configuration for the root user:

sudo crontab -e

This opens the root's crontab file in your default text editor.

3. Add the Reboot Command

In the crontab file, add the following line to schedule a reboot every day at 10 PM UTC (which is 2 AM Dubai time):

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

Explanation: - 0 22 * * * – This means every day at 22:00 (10:00 PM UTC). - /sbin/shutdown -r now – This tells the system to shut down and reboot immediately.

4. Save the File

Save and exit the text editor. The reboot will now be scheduled to occur every day at 10 PM UTC (which is 2 AM in Dubai).

5. Verify the Cron Job

You can verify that the cron job was successfully added by running:

sudo crontab -l

This will display the currently active cron jobs for the root user.

6. (Optional) Ensure the Correct Time Zone is Set for Your Server

If you'd like your server to handle time zones better, you can set the server's time zone to Dubai's time zone directly. You can do this with the following command:

sudo timedatectl set-timezone Asia/Dubai

Once you've done this, your server will automatically adjust for Dubai's time zone, and you can set the cron job to 2 AM without worrying about UTC conversion:

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

Let me know if you need further assistance!

Book a free 30min tailored consultation

Free first 30min of enterprise consultation to manage your business better using digital processes.


No comments yet.

Add a comment
Ctrl+Enter to add comment