web-dev-qa-db-ja.com

特定の時間に自動的にスリープおよびウェイクアップする

Ubuntu 10.10デスクトップを休止状態またはスリープ状態にして、翌日に「起動」させるにはどうすればよいですか?

Windowsでこれを実行できるソフトウェアを見てきましたので、Ubuntuでは難しくありません!

59
drnessie

rtcwake

興味のあるコマンドはrtcwakeです:

このプログラムは、指定されたウェイクアップ時間までシステムのスリープ状態に入るために使用されます。

検査

適切な構文を見つけるには、次を試してください。

Sudo rtcwake -u -s 60 -m mem

これにより、復元する前にコンピューターが60秒間中断されます。重要なパラメーターはmemです。選択できるオプションがいくつかあります。自分に最適な値を見つけるために再生します。

          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 [hh:mm]です

Sudo ./suspend_until 07:30

スクリプトをsuspend_untilという名前で保存し、実行権限を与えます。

chmod +x suspend_until

Cron

このスクリプトを呼び出すルートcronジョブを作成して、夕方の特定の時間に実行し、朝に目覚めることができます。

Sudo crontab -e

23:30にサスペンドスクリプトを実行するようなものを入力します。

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

suspend_untilスクリプト

#!/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 <[email protected]>
# 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!"

N.B.

スクリプトのこの部分のmemを、どんなサスペンドメソッドでも機能するように変更します。

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

ハードウェアクロックがUTC(-u)時間を使用するかローカル(-l)時間を使用するかによって、-uフラグの代わりに-lフラグを使用する必要がある場合もあります。ハードウェアクロックは、オペレーティングシステムで表示されるシステムクロックとは異なることに注意してください。

redgeonline へのクレジット

74
fossfreedom

Rtcwakeを使用して、単純なbashスクリプトを作成しました。 PHPを使用して自然言語をシステム時間に変換します。例えば:

  • Sudo ./cu "tomorrow 9am"

  • Sudo ./cu "next monday 3pm"

  • Sudo ./cu "1 hour ago"

    rtcwake: time doesn't go backward

ここからダウンロードできます

#!/bin/bash
export sdate=$1

date=`/usr/bin/php << 'EOF'
<?php
date_default_timezone_set("Etc/GMT-2");
$date = strtotime(GETENV("sdate"));
echo "\r".$date;
EOF`

rtcwake -m mem -t $date
5
albertolopez

rtcwakeはマシンに影響しませんでした。 Asusマザーボードでは、BIOSでウェイク時間を設定する必要がありました。この設定は[詳細設定]> [APM]メニューにあり、BIOS時刻が米国東部時間に設定されていてもUTCを使用する必要がありました。