30

I want my PC to sleep at 04:58 and wake at 05:15, every day.

How do I do that?

1

4 Answers 4

34

How to Make Your Linux PC Wake From Sleep Automatically

Want to put your Linux PC into sleep or hibernate mode and have it automatically wake at a specific time? You can easily do this with the rtcwake command, included by default with most Linux systems.

This can be useful if you want your computer to do something at a specific time, but don’t want it running 24/7. For example, you could put your computer to sleep at night and have it wake up before you do some downloads.

Using rtcwake

The rtcwake command requires root permissions, so it must be run with sudo on Ubuntu and other Ubuntu-derived distributions. On Linux distributions that don’t use sudo, you’ll have to log in as root with the su command first.

Here’s the basic syntax of the command:

sudo rtcwake -m [type of suspend] -s [number of seconds]

For example, the following command suspends your system to disk (hibernates it) and wakes it up 60 seconds later:

sudo rtcwake -m disk -s 60

Types of Suspend

The -m switch accepts the following types of suspend:

standby – Standby offers little power savings, but restoring to a running system is very quick. This is the default mode if you omit the -m switch.

mem – Suspend to RAM. This offers significant power savings – everything is put into a low-power state, except your RAM. The contents of your memory are preserved.

disk – Suspend to disk. The contents of your memory are written to disk and your computer is powered off. The computer will turn on and its state will be restored when the timer completes.

off – Turn the computer off completely. rtcwake’s man page notes that restoring from “off” isn’t officially supported by the ACPI specification, but this works with many computers anyway.

no – Don’t suspend the computer immediately, just set the wakeup time. For example, you could tell your computer to wake up at 6am. After that, can put it to sleep manually at 11pm or 1am – either way, it will wake up at 6am.

Seconds vs. Specific Time

The -s option takes a number of seconds in the future. For example, -s 60 wakes your computer up in 60 seconds, while -s 3600 wakes your computer up in an hour.

The -t option allows you to wake your computer up at a specific time. This switch wants a number of seconds since the Unix epoch (00:00:00 UTC on January 1, 1970). To easily provide the correct number of seconds, combine the date command with the rtcwake command.

The -l switch tells rtcwake that the hardware clock is set to local time, while the -u switch tells rtcwake that the hardware clock (in your computer’s BIOS) is set to UTC time. Linux distributions often set your hardware clock to UTC time and translate that to your local time.

For example, to have your computer wake up at 6:30am tomorrow but not suspend immediately (assuming your hardware clock is set to local time), run the following command:

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

Help

4
  • 1
    A nice rtcwake write-up is at this question. It offers complete solution: askubuntu.com/questions/61708/…
    – gare
    Dec 25, 2013 at 14:42
  • 9
    Please when you copy paste from a website give at least the url: howtogeek.com/121241/…
    – hanoo
    Mar 28, 2015 at 19:56
  • It seems that rtcwake cannot remember multiple instances, so how do I make the computer wake up, say, every hour? Oct 11, 2017 at 18:00
  • 1
    Any reason you don't use --date argument? E.g. I use sudo rtcwake -m mem --date 08:55 to wake my computer at that time (I use 24h format). The parameter seem to accept all same arguments as the $(date …) subcommand you used.
    – Hi-Angel
    Jan 20, 2021 at 6:18
9

You can do (at least half of) this with Gnome Schedule. (sudo apt-get install gnome-schedule) (NB: it gets put in your launcher as Scheduled Tasks, though typing gnome-schedule still brings it up.)

After launching it, "New" -> "Recurrent Task". Fill in the form as you see fit.

The command to hibernate is /usr/sbin/pm-hibernate (Suspend is /usr/sbin/pm-suspend)

In regards to waking up again, please see "How do I schedule waking up from hibernation?"


Alternately, you can install the "power management interface". (sudo apt-get install powermanagement-interface)

Then create a script like this:

#!/bin/bash
# This script puts the system under standby mode for x hours
usage() {
echo "usage: $0 <n-hours>"
echo "where <n-hours> is the number of hours to be on standby"
exit 0

}
if [ $# -ne 1 ]
then
usage
fi

PATH=$PATH:/usr/sbin
hours=$1
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d "+ $hours hours"` > /sys/class/rtc/rtc0/wakealarm
## Edit the above line to get the exact length of hibernation you want
pmi action suspend

And schedule it in the root's crontab.

Source

0
2

You can try setting up BIOS for a wake up event, Almost every motherboard have that feature, use your mb manual and figure out it, in some AMI bios, it is called Wake up by RTC alarm, I think that is the easy way to wake up the PC at a specific time

1

So if anyone is interested this is what I found that works, without having to install anything and as non-root.

Use this command Code:

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

and to delay it use the sleep command with a number with either s m h or d (sec, min, day, hour) and with a ;

example Code:

sleep 60s; dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

That suspends the computer after 60 seconds

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .