2

The purpose of the script is to re-enable a hidden SSID upon resume from sleep. Somehow the ability to restart a hidden SSID automatically was lost when I upgraded from 18.04 LTS to 20.04 LTS.

You can see from the script below how many ways I have tried to get this to work. The echo print to suspend.txt works every time upon resume. It is just the portion to restart the wifi that does not work.
All the commands I tried in the script work as expected when entered on the CLI and the /home/user/Desktop/wifi-ssid.sh works when double clicked.

The results from journalctl | grep systemd-sleep is below the script. Most notable is the error...

"Error: Connection activation failed: No suitable device found for this connection (device lo not available because device is strictly unmanaged)."

This must be something simple. Please help.


#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/user/Desktop

case "$1" in pre) #code execution BEFORE sleeping/hibernating/suspending ;; post) #code execution AFTER resuming echo "$(date) - $1: test pre" >> /home/user/tmp/suspend.txt /usr/bin/nmcli c up id "SSID" #/usr/bin/nmcli radio wifi on #sleep 2 #/usr/bin/nmcli c up id "SSID" #/home/user/Desktop/wifi-ssid.sh #su user -c "/home/user/Desktop/wifi-ssid.sh" #su user -c "/usr/bin/nmcli c up id "SSID"" #/usr/bin/sudo -u user bash -c "export XDG_RUNTIME_DIR=/run/user/1000; /home/user/Desktop/wifi-ssid.sh" #/usr/bin/sudo -u user bash -c "export XDG_RUNTIME_DIR=/run/user/1000; /usr/bin/nmcli c up id "SSID"" #/usr/bin/sudo -u user bash -c "/home/user/Desktop/wifi-ssid.sh"
#su user -c "/usr/bin/nmcli con up SSID" #/usr/bin/sudo -u user bash -c "export XDG_RUNTIME_DIR=/run/user/1000; /usr/bin/nmcli con up SSID; /usr/bin/nmcli radio wifi on; sleep 2; /usr/bin/nmcli c up id "SSID""

 ;;

esac

exit 0


journalctl | grep systemd-sleep shows the following:

Mar 03 16:53:30 User systemd-sleep[4074]: Suspending system...  
Mar 03 20:01:32 User systemd-sleep[4074]: System resumed.  
Mar 03 20:01:32 User systemd-sleep[4206]: /dev/sda:  
Mar 03 20:01:32 User systemd-sleep[4206]:  setting Advanced Power Management level to 0xfe (254)  
Mar 03 20:01:32 USer systemd-sleep[4206]:  APM_level = 0  
Mar 03 20:01:32 User systemd-sleep[4189]: Error: Connection activation failed: No suitable device found for this connection (device lo not available because device is strictly unmanaged).
Raffa
  • 32,237
toddk63
  • 141

1 Answers1

4

Networking is not made available until all scripts in the /lib/systemd/system-sleep directory finish executing.

Try sending networking related commands to the background with a delay of e.g. 10 seconds in a sub-shell and detach it i.e. change:

/usr/bin/nmcli c up id "SSID"

to:

(sleep 10; /usr/bin/nmcli c up id "SSID") & disown

Notice that disown is a bash builtin and depending on your system shell configuration /bin/sh might be linked to a different shell command interpreter other than bash .... For such case, you might call /bin/bash using a command string like so:

/bin/bash -c '(sleep 10; /usr/bin/nmcli c up id "SSID") & disown'

Or even in most cases calling /bin/sh with a sub-shell in a command string i.e. like so:

/bin/sh -c '(sleep 10; /usr/bin/nmcli c up id "SSID") &'

should fork a new detached process.

Another thing that you might need to keep that process alive is to explicitly specify/switch to a user e.g. your username or even root if your command/script requires elevated privileges to execute ... You can do this as well in a command string style but, you need to use different quoting style i.e. double quotes /bin/su username -c "/bin/bash -c '...'" e.g. like so:

/bin/su username -c "/bin/bash -c '(sleep 10; /usr/bin/nmcli c up id SSID) & disown'"

changing username to a valid account's user name on the system e.g. your actual account login user name.

Raffa
  • 32,237
  • Your last two suggestions did not work, but the 'Error:' went away in journalctl.The first suggestion returned an error ':disown: not found' – toddk63 Mar 04 '23 at 14:18
  • @toddk63 I have updated the answer for that one on how to keep the background process alive until it does its job. – Raffa Mar 04 '23 at 15:28
  • 1
    It worked!...with "/bin/su root" but not "/bin/su username". Thank you for the help. – toddk63 Mar 04 '23 at 18:51
  • @toddk63 You are welcome ... You did change username to e.g. your actual account login user name ... If so, then your command requires elevated privileges to execute and specifying root as a user is mandatory in such case. – Raffa Mar 04 '23 at 19:02
  • Yes I did try actual "username", so "root" was required – toddk63 Mar 04 '23 at 21:30
  • /bin/su root -c "/bin/bash -c '(sleep 10; /usr/bin/nmcli c up id SSID) & disown'" – toddk63 Mar 04 '23 at 21:31