Home Command line utilities Automatically Wake Up Your Linux System From Sleep Or Hibernation Mode

Automatically Wake Up Your Linux System From Sleep Or Hibernation Mode

By sk
Published: Last Updated on 21.4K views

Today, we will be discussing an useful topic that describes how to automatically wake up your Linux system from sleep or hibernation mode using 'Rtcwake' utility. The rtcwake is used to enter a Linux system sleep or hibernate state, and automatically wake it up at a specific time. There is no need to power off and power on your system again. Just put your system into sleep or hibernate mode, and come back after the specified time and start dong your stuffs.

A word of caution:

Please note that RTC stands for real-time clock. It is actually your hardware clock which can be set in your BIOS. If you have CMOS battery or bios problem, this command will not work. You need to set correct time in BIOS to use rtcwake properly. Also, you need to be careful while using this utility, because it requires root permission to work. Any misuse of this utility may crash the Kernel and/or system.

Automatically Wake Up Your Linux System From Sleep Or Hibernation Mode Using 'rtcwake' Utility

Rtcwake comes pre-installed with most Linux operating systems by default, so don't bother installing it. Let me show you some practical examples. I tested the following commands on my Arch Linux desktop, and they worked well as I expected.

The typical syntax of rtcwake command is:

$ rtcwake [options] [-d device] [-m standby_mode] {-s seconds|-t time_t}

Wake up system after a specific time

First of all, make sure you have closed any running programs or saved any opened documents before running this program. The rtcwake command requires root permissions to work.

Let us now suspend our system and wake it up after 60 seconds. To do so, run:

$ sudo rtcwake -m disk -s 60

Sample output would be:

rtcwake: assuming RTC uses UTC ...
rtcwake: wakeup from "disk" using /dev/rtc0 at Fri Apr 21 09:04:49 2017

Wake up system after a specific time

Here,

  • -m indicates the mode.
  • -s indicates the system's wakeup time. In our case, we have given 60 seconds.

The rtcwake command supports the following modes.

  • standby - This is the default mode, if you didn't mention the -m switch in your command. This state offers minimal, though real, power savings, while providing a very low-latency transition back to a working system.
  • freeze - In this mode, all processes are frozen, all the devices are suspended and all the processors idled.
  • mem - Suspend-to-RAM. In this state, everything will be put into low-power state, except memory to offer significant power savings. The contents of the RAM are retained.
  • disk - Suspend-to-disk. This state offers the greatest power savings. This state operates similarly to Suspend-to-RAM, but includes a final step of writing memory contents to disk.
  • off - It shuts down your pc completely. This is done by calling '/sbin/shutdown'. Not officially supported by ACPI, but it usually works.
  • no - Don't suspend, only set the RTC wakeup time.
  • on - Don't suspend, but read the RTC device until an alarm time appears. This mode is useful for debugging.
  • disable - Disable a previously set alarm.
  • show - Prints the alarm information in format: "alarm: off|on <time>". e.g. "alarm: on Fri Apr 21 15:00:05 2017".

Wake up system at a specific time

We can also wake our system up at a specific time using -t option as shown in the below example.

$ sudo rtcwake -m no -l -t "$(date -d 'today 16:00:00' '+%s')"

Sample output:

Here,

  • -m no - This option doesn't suspend the pc, only sets the RTC wakeup time.
  • -l - Indicates the local time set in Bios.
  • -t $(date +%s -d ‘today 16:00:00’) - Sets  the  wakeup  time to 4pm today.

Useful Tip: To learn what each argument in a Linux/Unix command does, check out Explainshell.


If you want to wake up your system tomorrow at a specific time, the command would be:

$ sudo rtcwake -m no -l -t $(date +%s -d 'tomorrow 10:00')

The above command will wake up your system at 10 am tomorrow, but won't suspend it immediately.

To wake up your system at a specific date and time:

$ sudo rtcwake -m no -l -t "$(date -d '2017-04-25 16:00:00' '+%s')"

Additionally, you can run a specific program after waking your system up using "&&" operator as shown in the following example.

$ sudo rtcwake -m mem -s 60 && chromium

The above command suspends our system to RAM and wakes it up after 60 seconds and launches the chromium web browser. Cool, isn't it?

For more details, refer man pages.

$ man rtcwake

Suggested read:


And, that's all. Now, you know how to wake up your computer running with Linux automatically at or after specific time from sleep or hibernation.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

1 comment

William Barath November 2, 2017 - 8:31 pm

If like me you find that rtcwake wakes instantly instead of at the correct time, try this:

$ sleep 3; sudo rtcwake -m mem -s 60

With some USB keyboards the bus can take a while to settle down after you hit enter.

I’m going to go file a bug against rtcwake to check whether stdin is a tty and if so, wait a second or three.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More