如何使Linux PC自动从睡眠中唤醒

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.

是否要将Linux PC置于睡眠或Hibernate模式并在特定时间自动唤醒? 您可以使用rtcwake命令轻松完成此操作,大多数Linux系统默认包含该命令。

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.

如果您希望计算机在特定时间执行某项操作,但又不想24/7全天候运行,则此功能很有用。 例如,您可以让计算机在晚上入睡,并在执行某些下载之前将其唤醒。

使用rtcwake (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.

rtcwake命令需要root权限,因此它必须在Ubuntu和其他Ubuntu衍生发行版上以sudo运行。 在不使用sudo的Linux发行版上,您必须首先使用su命令以root用户身份登录。

Here’s the basic syntax of the command:

这是命令的基本语法:

sudo rtcwake -m [type of suspend] -s [number of seconds]

sudo rtcwake -m [暂停类型] -s [秒数]

For example, the following command suspends your system to disk (hibernates it) and wakes it up 60 seconds later:

例如,以下命令将您的系统挂起到磁盘(使其Hibernate)并在60秒后将其唤醒:

sudo rtcwake -m disk -s 60

sudo rtcwake -m磁盘-s 60

image

暂停类型 (Types of Suspend)

The -m switch accepts the following types of suspend:

-m开关接受以下类型的挂起:

  • 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.

    待机 –待机几乎没有节电,但是恢复到正在运行的系统非常快。 如果省略-m开关,则这是缺省模式。

  • 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.

    内存 –挂起到RAM。 这样可以节省大量电量–除RAM外,所有其他设备都进入低功耗状态。 内存中的内容将保留。

  • 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.

    disk –挂到磁盘。 内存中的内容将写入磁盘,并且计算机已关闭电源。 计时器完成后,计算机将打开电源并恢复其状态。

  • 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.

    关闭 –完全关闭计算机。 rtcwake的手册页指出,ACPI规范并未正式支持从“ off”进行还原,但是无论如何,这适用于许多计算机。

  • 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.

    –不要立即挂起计算机,只需设置唤醒时间即可。 例如,您可以告诉计算机在早上6点醒来。 之后,可以将其手动设置为晚上11点或凌晨1点-无论哪种方式,它将在早上6点醒来。

秒vs.特定时间 (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.

-s选项将在未来花费几秒钟。 例如,-s 60在60秒内唤醒计算机,而-s 3600在一个小时内唤醒计算机。

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.

-t选项可让您在特定时间唤醒计算机。 自Unix时代(1970年1月1日UTC:00:00:00)以来,此开关需要几秒钟的时间。 为了轻松提供正确的秒数,请将date命令与rtcwake命令结合使用。

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.

-l开关告诉rtcwake硬件时钟设置为本地时间,而-u开关告诉rtcwake硬件时钟(在计算机的BIOS中)设置为UTC时间。 Linux发行版通常将您的硬件时钟设置为UTC时间,并将其转换为本地时间。

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:

例如,要使您的计算机明天早上6:30醒来但不立即挂起(假设您的硬件时钟设置为本地时间),请运行以下命令:

sudo rtcwake -m no -l -t $(date +%s -d ‘tomorrow 06:30’)

须藤rtcwake -m no -l -t $(date +%s -d'明天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将系统从睡眠状态唤醒后,使用&&运算符运行特定命令。 例如,以下命令将您的计算机挂起到RAM,两分钟后将其唤醒,然后启动Firefox:

rtcwake -m mem -s 120 && 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.

将rtcwake命令集成到cron脚本中,以在特定时间自动唤醒计算机。 -m no开关在cron脚本中也很有用。 例如,您可以每天晚上10点在cron脚本中运行rtcwake -m no -s 28800命令。 这样可以使您的计算机在6:00 am唤醒28800秒。 但是,您的计算机不会立即进入睡眠状态-您可以将其设置为晚上11点或凌晨1点进入睡眠状态,并且它通常仍会在早上6点唤醒。

注意事项 (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.

    RTC代表实时时钟。 rtcwake使用计算机的硬件时钟(可以在BIOS中设置)确定计算机何时唤醒。 如果您使用的旧计算机上的CMOS电池即将耗尽,则无法使时钟正常运行,则将无法使用。
  • 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.

    如果睡眠,挂起RAM或Hibernate不能在您的Linux系统上正常工作-可能是因为Linux没有使它们在您的硬件上正常工作的驱动程序-这可能无法正常工作。
  • 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.

    将笔记本电脑设置为在特定时间自动唤醒时要小心。 您不希望它在笔记本电脑包中醒来,运行,过热或耗尽电池。

翻译自: https://www.howtogeek.com/121241/how-to-make-your-linux-pc-wake-from-sleep-automatically/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值