How do I suspend over ssh?
Solution 1
For me the simplest is to use the at
command:
echo 'pm-suspend' | sudo at now + 2 minutes
Then disconnect from SSH session.
Solution 2
Just type <enter>~&
(that's three keystrokes: enter, squggle, ampersand) and ssh will go into the background, and eventually timeout by itself. That's good if you want to just abandon an interactive session in a case like this.
Or, alternatively, put that into a shell script on MyLocalPC and connect in a way that will background the connection:
ssh -f MyLocalPC go-to-sleep
Solution 3
You need to enable the X11 forwarding using ssh -Y
. Alternatively, use at now + 2 minutes
to run the command only once (see man at
for more information).
Solution 4
set a cron job for 2 minutes in the future and disconnect
Related videos on Youtube
sdaau
Updated on September 18, 2022Comments
-
sdaau over 1 year
I guess this question is pretty much the same as How to configure dbus to allow ssh-user to suspend server?; except I wanted to formulate it better.
Assume I have an Ubuntu server running nonstop, let's call it
MyServer
. Let's say then, I have another PC on the same local network asMyServer
, let's call itMyLocalPC
.MyLocalPC
is then kept in suspend, unless it is turned on viawakeonlan
byMyServer
. This part of the process works perfectly for me: I can log in viassh
toMyServer
, and on theMyServer
ssh prompt I can issuewakeonlan
, andMyLocalPC
wakes up - great.Then, however, as soon as I'm done working with
MyLocalPC
, I'd like to put it into suspend again. The problem is as follows - I can put the machine in suspend easy, if I ssh intoMyLocalPC
first viassh
:[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
This will suspend
MyLocalPC
- but will also block thessh
exiting properly, and eventually thessh
toMyServer
ends up frozen. I try to get tricky and issue something like this:[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.
Then I read somewhere
DISPLAY
variable should be defined - but that fails too:[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
So does anyone know how can I issue a suspend to
MyLocalPC
, without thessh
connection toMyServer
freezing? -
sdaau about 13 yearsHi @aking1012 - thanks for that, I'll give it a try and report back.... Cheers!
-
poolie about 13 years
at
would be a better choice thancron
if you just need a single job to run a bit later, or even better justsleep 2m && blah
. -
RobotHumans about 13 years@poolie - good point
-
sdaau about 13 yearsThanks @poolie for the answer - will have to report back with what I ended up choosing, I just wanted to +1 for now :) Cheers!
-
sdaau about 13 yearsThanks for the answer, @Adam Byrtek - good info on X11 forwarding..