Power off and reboot Ubuntu Linux server after predefined time

Tobias Etzold • September 7, 2026

linux

I have a tiny server for my own applications in my local network. But this server doesn't need to run 24/7. So one day I thought about how could I turn it off at a specific time and reboot it automatically after some time to save some money on my electricity bill.

Turns out, there is a tool called rtcwake. This tool allows you to set the system to start at a specific time or date.

But first you should test your local timezone settings. Under Ubuntu you just need to call timedatectl status. If this is already set correctly you are good to go. But if you need to change it, because your server is running in another timezone, you can change it with sudo timedatectl set-timezone Europe/Berlin. This is just an example. Change the timezone as it fits your needs. Afterwards don't forget to restart cron. This can be achieved with sudo service cron restart.

The next step is to add a job to your crontab. Just start editing it with sudo crontab -e. When it's the first time you edit your crontab, it will ask you to choose an editor. Just choose what you prefer. The simplest is nano.

At the end of your crontab file add the following, if you want to set your server to sleep every night from midnight to 8 o'clock.

0 0 * * * /usr/bin/rtcwake -m no --date +480min && /sbin/shutdown -P now

The first 0 is for the minute the job shoud start and the second for the hour. The three asterisks (stars) are for date of month, month and date of week as the job should run on any of them. This is followed by to commands which run one after another. The first one sets the rtc clock to wake the server in 8 hours. The second command powers the server down.

After you saved your changes you are good to go. At midnight your server will shut down by itself and restart 8 hours later.