fos*_*dom 81
您感兴趣的命令是rtcwake
:
该程序用于进入系统休眠状态,直到指定的唤醒时间。
要找到适合您的正确语法,请尝试以下操作:
sudo rtcwake -u -s 60 -m mem
Run Code Online (Sandbox Code Playgroud)
这应该在恢复之前暂停计算机 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.
Run Code Online (Sandbox Code Playgroud)
一个脚本(在这篇文章的底部)可用于暂停您的计算机并在特定时间唤醒:
语法是suspend_until [hh:mm]
例如
sudo ./suspend_until 07:30
Run Code Online (Sandbox Code Playgroud)
将脚本保存为名称suspend_until
并赋予它执行权限即
chmod +x suspend_until
Run Code Online (Sandbox Code Playgroud)
您可以创建一个根 cron 作业,调用此脚本在晚上的特定时间执行,然后在早上醒来:
sudo crontab -e
Run Code Online (Sandbox Code Playgroud)
现在输入类似在 23:30 运行挂起脚本的内容:
30 23 * * * /home/myhomefolder/suspend_until 07:30
Run Code Online (Sandbox Code Playgroud)
sudo rtcwake -u -s 60 -m mem
Run Code Online (Sandbox Code Playgroud)
NB
更改mem
脚本的这一部分以使用适合您的挂起方法:
# Set RTC wakeup time
sudo rtcwake -l -m mem -t $DESIRED &
Run Code Online (Sandbox Code Playgroud)
您可能还需要根据您的硬件时钟是使用 UTC ( ) 还是本地 ( ) 时间来替换-u
标志来代替标志。请注意,您的硬件时钟与您在操作系统中看到的系统时钟不同。-l
-u
-l
归功于redgeonline
小智 5
我使用 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
Run Code Online (Sandbox Code Playgroud)