Score:0

Send ssh command before/after suspending

cn flag

I need your help;

How to send ssh command before suspending, and after wake up? I tried with /usr/lib/systemd/system-sleep/ script, but I ran into "Network is unreachable" error, because Wifi is disabled during script runs.

I'm running KDE 20.04

Many thanks!

Update: The Network disconnection comes not from me. Normally its on. But when sleep mode run, the Network disconnect. So how to run my script, before the Network braek down?

For more detail; my Laptop should send an commend to smart socket, whitch toggle external monitor and power supply, if lid is closed.

Sadaharu Wakisaka avatar
pl flag
Welcome to AskUbuntu, you can send `ssh` command anytime while network alive. The machine doesn't recognize itself while sleeping, so the script should be a part of confirmation of network status and an execute part of `ssh`.
Score:0
ar flag

Try:

Add the following two lines to your systemd script:

Requires=network-online.service
After=network-online.service

I have not tried this. So, it may not work. Please see all the links below and try other solutions listed there.

Sources: https://unix.stackexchange.com/questions/257888/systemd-wait-for-network-interface-to-be-up-before-running-service

https://unix.stackexchange.com/questions/126009/cause-a-script-to-execute-after-networking-has-started

How can I make my systemd service wait for a network interface?

https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

Hope this helps

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.