0

I have following script saved it /lib/systemd/system-sleep/ directory, to run after every wake-up from suspend:

#!/bin/bash
if [ "$1" == "post" ]; then
    sleep 5
    cni=$(ip link | grep "state UP" | grep --only-matching --perl-regexp '(?<=:).*(?=:)' | tr --delete ' ')
    #cni=connected(UP) network interface(s)
    if [ -z "$cni" ] && [ $(nmcli radio wifi) == "disabled" ]; then
    #export DISPLAY=:0
    #su -c - my_user nmcli radio wifi on
    nmcli radio wifi on
    fi
fi

I tested it, logged in as regular user, then in terminal su - root and run it with switch "post" it works as expected and when there is no network adapter connected and wifi is down, it enables WIFI. However it's not working when I actually suspend and wake up my laptop. I was reading that maybe I have to define DISPLAY variable and run it as regular user, but still it didn't help. Any idea what am I missing here ?

EDIT - added shebang at the beginning of script, forgot to write it here, but it's my in script

Ubuntu 17.04 kernel 4.10.0-21-generic

mauek unak
  • 218
  • 3
  • 12
  • What is the ubuntu version ? Check these pages https://askubuntu.com/questions/226278/run-script-on-wakeup https://askubuntu.com/questions/92218/how-to-execute-a-command-after-resume-from-suspend – G helmor Jun 04 '17 at 14:11
  • added ubuntu version and kernel – mauek unak Jun 04 '17 at 15:39
  • G helmor do you suggest that in Ubuntu 17.04 should be used different path ? because I used path from one of the answers from your link, and it is working when i try to create/copy files and write to them. But nmcli is not working when waking up from suspend .. – mauek unak Jun 04 '17 at 15:44

1 Answers1

0

You are using bash features, but letting systemd run your script with /bin/sh. Put a #!/bin/bash at the beginning, or rewrite your script to only use sh features.

waltinator
  • 36,399