我正在使用 Ubuntu 10.04 系统。我试图在特定时间自动唤醒我的系统。为此,我编写了一个用于自动唤醒的 Python 脚本。该脚本运行完美,我在此位置进行了检查/sys/class/rtc/rtc0/wakealaram.唤醒时间已成功写入此处瓦克拉拉姆文件。但系统未在指定时间唤醒。如果您对这个问题有任何想法,请告诉我。这对我非常有用。
答案1
唤醒
您感兴趣的命令是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
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!"
克罗恩
您可以创建一个 root cron 作业,调用此脚本在晚上的特定时间执行,然后在早上醒来:
sudo crontab -e
现在输入类似的内容在 23:30 运行暂停脚本:
30 23 * * * /home/myhomefolder/suspend_until 07:30
笔记:
将脚本的这一部分更改mem
为适合您的任何暂停方法:
# Set RTC wakeup time
sudo rtcwake -l -m mem -t $DESIRED &
您可能还必须用-u
标志替换 标志,-l
具体取决于您的硬件时钟使用的是 UTC ( -u
) 还是本地 ( -l
) 时间。请注意,您的硬件时钟与您在操作系统中看到的系统时钟不同。
如果您愿意,您可以像os.system
往常一样将其转换为 Python 脚本。
来源:问库本图
答案2
Ubuntu 不直接支持此功能。
BIOS 需要具有正确的功能。
本页描述了该功能http://www.mythtv.org/wiki/ACPI_Wakeup
因此,除非您的 BIOS 支持它,否则世界上所有的命令都无济于事。