I've written a script to periodically check whether my network is up by pinging three major sites and disconnecting and then reconnecting my network if all three fail. This script works fine from the command line, even if I don't have an X session. The script looks like this:
#!/bin/bash /usr/bin/notify-send -i 'dialog-information' 'Running CheckNetUp.sh' 'Checking whether network is up' AtLeastOneSiteFound=false; # Try to download three sites and indicate a site was found if they work # as long as we can grab at least one site, we're good. # Otherwise, we'll disconnect and reconnect. /usr/bin/wget --spider --read-timeout=15 http://google.ca if [ "$?" = 0 ]; then AtLeastOneSiteFound=true; fi /usr/bin/wget --spider --read-timeout=15 http://facebook.com if [ "$?" = 0 ]; then AtLeastOneSiteFound=true; fi /usr/bin/wget --spider --read-timeout=15 http://wikipedia.org if [ "$?" = 0 ]; then AtLeastOneSiteFound=true; fi if [ "$AtLeastOneSiteFound" = false ]; then # Disconnect my wifi (and, consequently, VPN) /usr/bin/nmcli dev disconnect wlp0s20u2 # Bring my wifi up /usr/bin/nmcli con up uuid e23f4af0-7411-4f4e-8d3c-a7cd35b607e1 # Bring my VPN up /usr/bin/nmcli con up uuid 6b0f8740-df8e-411e-adeb-bcf70ced772f fi
Here's the problem: the script fails in cron with this error message when it tries to bring up the wifi:
Error: Connection activation failed: Not authorized to control networking.
I've found a bunch of potential solutions online, but no luck so far. Most promising seemed to be making the wifi and VPN connections system connections/accessible to all users with the passwords in the text configuration but that didn't change anything.
EDIT: The script is running under my user in both the crontab and when run manually.