从 cron 休眠

Anm*_*ggi 3 cron hibernate automation systemd 16.04

我正在尝试使用命令从 cron 休眠systemctl hibernate。但是,我收到以下错误:

Failed to set wall message, ignoring: Interactive authentication required.
Failed to hibernate system via logind: Interactive authentication required.
Failed to start hibernate.target: Interactive authentication required.
See system logs and 'systemctl status hibernate.target' for details.
Run Code Online (Sandbox Code Playgroud)

如果我从终端手动执行上述命令,它会按预期工作。

如何从 cron 休眠?

我使用的是 Ubuntu 16.04。

use*_*.dz 5

发生这种情况是因为它需要 root 权限。解决方案是使用而不是
添加 hibernate 命令。sudo crontab -e -u rootcrontab -e

作为非特权用户,polkit对于电源管理是必需的。如果您位于本地 systemd-logind 用户会话中并且没有其他会话处于活动状态,则以下命令无需 root 权限即可运行。如果没有(例如,因为另一个用户登录到 tty),systemd 将自动询问您 root 密码。

电源管理命令:

systemctl reboot|poweroff|suspend|hibernate|hybrid-sleep
Run Code Online (Sandbox Code Playgroud)

参考: https: //wiki.archlinux.org/index.php/Systemd#Power_management