如何通过 ssh 挂起?

sda*_*aau 6 server ssh suspend dbus

我想这个问题与如何配置 dbus 以允许 ssh-user 挂起服务器几乎相同; 除了我想更好地制定它。

假设我有一个不间断运行的 Ubuntu 服务器,我们称之为MyServer. 假设然后,我在与 相​​同的本地网络上有另一台 PC MyServer,我们称之为MyLocalPC

MyLocalPC然后保持挂起状态,除非通过wakeonlanby打开它MyServer。这部分过程对我来说非常适合:我可以通过sshto登录MyServer,在MyServerssh 提示下我可以发出wakeonlan,然后MyLocalPC醒来 - 很棒。

但是,一旦我完成了MyLocalPC,我想再次将其置于暂停状态。问题如下 - 如果我MyLocalPC首先通过ssh以下方式ssh 进入,我可以轻松地将机器挂起:

[MyServer]$ ssh MyLocalPC
[MyLocalPC]$ dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call --print-reply --reply-timeout=2000 /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend
Run Code Online (Sandbox Code Playgroud)

这将暂停MyLocalPC- 但也会ssh正确阻止退出,最终sshto最终被MyServer冻结。我试图变得棘手并发出这样的问题:

[MyServer]$ ssh MyLocalPC "dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call --print-reply --reply-timeout=2000 /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend"
Failed to open connection to "session" message bus: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
Run Code Online (Sandbox Code Playgroud)

然后我读到DISPLAY应该定义变量的地方- 但这也失败了:

[MyServer]$ ssh MyLocalPC "DISPLAY=:0 dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call --print-reply --reply-timeout=2000 /org/freedesktop/PowerManagement  org.freedesktop.PowerManagement.Suspend"
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.PowerManagement was not provided by any .service files
Run Code Online (Sandbox Code Playgroud)

那么有谁知道如何在MyLocalPC没有ssh连接到MyServer冻结的情况下向发出暂停?

Ada*_*tek 2

您需要使用 启用 X11 转发ssh -Y。或者,at now + 2 minutes仅用于运行该命令一次(请参阅man at参考资料 获取更多信息)。


Rob*_*ans 1

设置一个未来 2 分钟的 cron 作业并断开连接

  • 如果您只需要稍后运行一个作业,那么“at”将是比“cron”更好的选择,或者更好的是“sleep 2m && blah”。 (4认同)