如何从命令行hibernate/暂停,并在特定时间执行此操作
我设法通过阅读如何从命令行暂停/hibernate来了解如何从命令行暂停/hibernate系统? 。
但是,我想知道如何使用命令行在给定时间暂停/hibernate,绝对(例如,11PM)或相对(例如,30分钟)术语。
我已经知道如何使用shutdown来执行此操作,但我要确定命令是否相似。
您可以使用at
命令安排任何操作,包括运行该问题中详述的命令。
例如,如果要在30分钟内hibernate:
echo 'pmi action hibernate' | at now + 30 min
或者如果你想在晚上11点暂停:
echo 'pmi action suspend' | at 11pm
如果你需要以root
身份运行命令at
使用sudo
而不是命令本身运行sudo
(因为sudo
应该只能以交互方式运行,除非你已经配置它不要求你输入密码)。 例如,使用pm-hibernate
和pm-suspend
的上述命令的等价物是:
echo pm-hibernate | sudo at now + 30 min
echo pm-suspend | sudo at 11pm
对于相对规范(例如“30分钟后”),您只需使用sleep
命令使挂起/hibernate命令等待。
例子:
等待30分钟,然后暂停:
sudo sleep 30m; sudo pm-suspend
等待1小时,然后hibernate:
sudo sleep 1h; sudo pm-hibernate
对于重复的特定时间 – 例如关闭计算机是每天的特定时间。 用cron。
crontab -e
添加以下内容:
15 14 1 * * pmi action suspend
如果你想自定义它。
* * * * * command to be executed - - - - - | | | | | | | | | ----- Day of week (0 - 7) (Sunday=0 or 7) | | | ------- Month (1 - 12) | | --------- Day of month (1 - 31) | ----------- Hour (0 - 23) ------------- Minute (0 - 59)
对于一次性工作我们at at命令
例如,如果要在30分钟内hibernate:
echo 'pmi action hibernate' | at now + 30 min
或者如果你想在晚上11点暂停:
echo 'pmi action suspend' | at 11pm