SEARCH

How-To Geek

How to Make Your Linux PC Wake From Sleep Automatically

image

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 to perform 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

image

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’)

image

More Tips

Use the && operator to run a specific command after rtcwake wakes your system from sleep. For example, the following command suspends your computer to RAM, wakes it two minutes later, and then launches Firefox:

rtcwake -m mem -s 120 && firefox

Integrate the rtcwake command into a cron script to automatically wake your computer at a specific time. The -m no switch can also be useful in a cron script. For example, you could run the rtcwake -m no -s 28800 command in a cron script at 10pm every day. This would set your computer to wake up in 28800 seconds at 6:00am. However, your computer wouldn’t go to sleep immediately – you could put it to sleep at 11pm or 1am and it would still wake at 6am normally.

Caveats

  • RTC stands for real-time clock. rtcwake uses your computer’s hardware clock, which you can set in your BIOS, to determine when your computer will wake up. If you’re using an old computer with a dying CMOS battery that can’t keep the clock running properly, this won’t work.
  • If sleep, suspend to RAM, or hibernate don’t work properly with your Linux system – perhaps because Linux doesn’t have the drivers to make them work properly with your hardware – this may not work.
  • Be careful when setting a laptop to automatically wake at a specific time. You wouldn’t want it waking up, running, and overheating or running down its battery in a laptop bag.

Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 08/8/12

Comments (8)

  1. badger_fruit

    Useful, thanks!

  2. snowhawkyrf

    Very useful! I can make my PC to wake up in the morning and play a song to wake me up now : )

  3. siva sundar

    very useful. when we go out for a ride and come back we can ensure that our pc is fully functioning. Its saves power.

  4. Kostas

    Very useful,
    I start to use my old pc to backup my network, go to sleep when finish and start over next day.

  5. Root

    What if your motherboard, chipset and BIOS has a conflict when resuming, which causes a kernel panic? That would be a major concern. Mine does that, quite annoying, maybe others can do a test to be sure? P4 boards might have that issue.

  6. Sandeep

    Works perfectly on HP ProBook 4530s. Thank you!

  7. Sandeep

    Oops! When my laptop wakes-up it’s screen is not locked. Yes, anybody can use it if I’m not around!! How to fix this?

    Thanks

  8. Sandeep

    Found a work-around:

    Set the wake-up time only ( #rtcwake -m no -s 30 ) and manually put it to any required state. When the computer wakes-up it will be locked.

    ref: man rtcwake

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!