1. Home
  2. Linux

How to automatically wake Linux up from sleep

Have you ever wanted your Linux PC to wake back up after putting it in sleep mode automatically? As it turns out, it is possible to set up any Linux operating system to wake up at specific times. In this guide as we show you how to set it up on your Linux PC!

Install RTCWake on Linux

RTCWake is the program we’ll be using to go over how to wake up the Linux operating system at arbitrary times automatically. However, the RTCWake application may not already be set up on your Linux PC, so before we get into how to use it, we must demonstrate how to install the program.

To start the installation of RTCWake on your Linux PC, launch a terminal window. To launch a terminal window, press Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. Then, with the terminal window open and ready to go, follow the command-line instructions outlined below that correspond with the OS you currently use.

Ubuntu

On Ubuntu Linux, users can quickly install the RTCWake application with the Apt command below.

sudo apt install util-linux

Debian

Those on Debian Linux can install the RTCWake program with the following Apt-get command.

sudo apt-get install util-linux

Arch Linux

Arch Linux users can easily install the RTCWake application with the following Pacman command.

sudo pacman -S util-linux

Fedora

If you’re using Fedora Linux and need to get your hands on the RTCWake app, use the following Dnf command in a terminal window.

sudo dnf install util-linux

OpenSUSE

On OpenSUSE Linux, users can install the RTCWake tool with the following Zypper command in a terminal window.

sudo zypper install util-linux

Generic Linux

RTCWake is a small program included in the “util-linux” package on most Linux operating systems. As a result, you should be able to get it working no matter how unknown your OS is.

To install RTCWake on lesser-known Linux operating systems, open up a terminal window and search for “util-linux.” Then, install it the way you typically install programs. Or, download the source code for “util-linux” from GitHub and try your hand at compiling it from scratch.

Using RTCWake to wake the system automatically

RTCWake works by reading your computer’s realtime clock, so be sure that your system’s CMOS battery is charged. Otherwise, RTCWake may not work correctly.

The RTCWake tool can suspend your computer to either disk or memory for a set time and wake it up again. For example, to suspend to memory with RTCWake only to wake it up 2 minutes later, you can run the following command in a terminal.

sudo rtcwake -u -s 120 -m mem

Or, if you prefer to suspend to disk, rather than to RAM, swap out the “mem” for “disk.”

sudo rtcwake -u -s 120 -m disk

Just take this command example and change it to exactly how long you want your system to go down before waking up. Keep in mind that since it is in seconds, you will need to calculate it to suit your needs.

sudo rtcwake -u -s (seconds) -m (mem or disk)

Waking up based on the date

RTCWake doesn’t only operate in seconds. It can also suspend and wake a system back up at a certain date or time. For instance, if you work on your Linux PC early in the mornings, around 9 am, RTCWake can be configured to wake up your Linux PC from suspension at that exact time.

Note: for this command, your system’s clock must be set to local time. Run sudo timedatectl set-local-rtc 1 in a terminal to switch to local time.

sudo rtcwake -m no -l -t $(date +%s -d ‘tomorrow 09:00’)

Automating RTCWake with Cron

The RTCWake application can be automated with a cron job, which is useful if you would prefer RTCWake to sleep and wake at the same time every day. To create a cron job, you must have cron set up on your Linux PC. Please follow our guide on cron to learn how to get it working.

Once you’ve gotten cron set up, use the command below to open up the crontab.

sudo EDITOR=nano crontab -e

With the crontab open, it’s time to create a custom cronjob that can automate wake/suspend. Take the example, and change “hour,” “minute,” and “seconds” in the command below.

Note: cron works based on 24-hour time. So, “hour” needs to be in 24-hour time for the command to work. For help converting 12-hour time to 24-hour time, click here.

hour minute * * * rtcwake -u -s seconds -m mem >/dev/null 2>&1

After writing out the command in the crontab, press Ctrl + O to save it, and exit the editor with Ctrl + X. Immediately upon exiting the crontab, cron will set RTCWake to work as you specified.

Leave a comment