Linux sleep and wake up

Automatically sleep and wake-up at specific times

How can I hibernate or sleep my Ubuntu 10.10 desktop and have it «wake up» the next day? I have seen software that can do this on windows, so it can’t be hard on Ubuntu!

4 Answers 4

rtcwake

The command that you are interested in is rtcwake :

This program is used to enter a system sleep state until specified wakeup time.

testing

To find the correct syntax that works for you try the following:

sudo rtcwake -u -s 60 -m mem 

This should suspend the computer for 60 seconds before restoring. The significant parameter is mem You have several options you can choose — play to find the value that works best for you:

 standby ACPI state S1. This state offers minimal, though real, power savings, while providing a very low-latency transi‐ tion back to a working system. This is the default mode. mem ACPI state S3 (Suspend-to-RAM). This state offers signif‐ icant power savings as everything in the system is put into a low-power state, except for memory, which is placed in self-refresh mode to retain its contents. disk ACPI state S4 (Suspend-to-disk). This state offers the greatest power savings, and can be used even in the absence of low-level platform support for power manage‐ ment. This state operates similarly to Suspend-to-RAM, but includes a final step of writing memory contents to disk. off ACPI state S5 (Poweroff). This is done by calling '/sbin/shutdown'. Not officially supported by ACPI, but usually working. no Don't suspend. The rtcwake command sets RTC wakeup time only. on Don't suspend, but read RTC device until alarm time appears. This mode is useful for debugging. 

suspend until a known time

A script (at the bottom of this post) could be used to suspend your computer and wake at a specific time:

syntax is suspend_until [hh:mm] for example

Save the script as the name suspend_until and give it execute rights i.e.

Читайте также:  Samba port no linux

Cron

You can create a root cron job that calls this script to execute at a specific time in the evening and then awake in the morning:

Now enter something like to run the suspend script at 23:30:

30 23 * * * /home/myhomefolder/suspend_until 07:30 

suspend_until script

#!/bin/bash # Auto suspend and wake-up script # # Puts the computer on standby and automatically wakes it up at specified time # # Written by Romke van der Meulen # Minor mods fossfreedom for AskUbuntu # # Takes a 24hour time HH:MM as its argument # Example: # suspend_until 9:30 # suspend_until 18:45 # ------------------------------------------------------ # Argument check if [ $# -lt 1 ]; then echo "Usage: suspend_until HH:MM" exit fi # Check whether specified time today or tomorrow DESIRED=$((`date +%s -d "$1"`)) NOW=$((`date +%s`)) if [ $DESIRED -lt $NOW ]; then DESIRED=$((`date +%s -d "$1"` + 24*60*60)) fi # Kill rtcwake if already running sudo killall rtcwake # Set RTC wakeup time # N.B. change "mem" for the suspend option # find this by "man rtcwake" sudo rtcwake -l -m mem -t $DESIRED & # feedback echo "Suspending. " # give rtcwake some time to make its stuff sleep 2 # then suspend # N.B. dont usually require this bit #sudo pm-suspend # Any commands you want to launch after wakeup can be placed here # Remember: sudo may have expired by now # Wake up with monitor enabled N.B. change "on" for "off" if # you want the monitor to be disabled on wake xset dpms force on # and a fresh console clear echo "Good morning!" 

Change mem in this part of the script for whatever suspend method works for you:

# Set RTC wakeup time sudo rtcwake -l -m mem -t $DESIRED & 

You may also have to substitute the -u flag in place of the -l flag depending on whether your hardware clock uses UTC ( -u ) or local ( -l ) time. Note that your hardware clock is different from the system clock you see in your operating system.

Источник

Put Linux server into sleep and wake it up using WOL packets

I am looking for a way to put my Linux home server in standby after a period without any «heart beat» network activity. I would like to use WOL packets as a heart beat signal. These packages will be send by several clients each with an interval of, lets say, every 15 minutes. An actual example is therefore more than welcome.

Читайте также:  Linux create directory chain

Why not just disable standby on the server? In my world, servers and standby should never be in the same sentence, unless people tells you not to do it 😉

Because I do not want my home server to be powered on the whole day. But only when PC’s are powered on, or smartphones te be in WiFi range.

Thanks for you suggestion. Currently the server does not go into standby by itself. The solution that I am looking for should take care of this as well. I am planning to add service monitoring, to prevent the server going to sleep while, for example, a backup process is running. But first things first. 😉

@ChrisS «Modern hardware ‘wears’ the…» Well, sort of. A power/heat cycle does induce a certain amount of wear. But so does running it. That power cycle is the same as running it for X time. So, if X is less than the amount of time you had it not running, you’re prolonging life. If X is greater, you’re shortening life. I doubt X is more than a few hours, even for the worst-case component. (A lot of components are expected to have rapid heat cycling, e.g, the CPU)

Источник

Suspend and wake PC at certain time

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:

Читайте также:  Kerio control vpnclient linux

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

Источник

Оцените статью
Adblock
detector