Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


/usr/bin/notify-send -i 'dialog-information' 'Running CheckNetUp.sh' 'Checking whether network is up'


# 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

/usr/bin/wget --spider --read-timeout=15 http://facebook.com
if [ "$?" = 0 ]; then

/usr/bin/wget --spider --read-timeout=15 http://wikipedia.org
if [ "$?" = 0 ]; then

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

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.

share|improve this question
So is your script running from your user crontab, or from the system crontab? Under what user do you run it manually? – Greg Hewgill Sep 2 '14 at 23:58
It runs under my user for both. I'll add that to the question. – Dylan Sep 3 '14 at 0:00
Have you tried running the above script from the system /etc/crontab? nmcli might be doing some tricky things so that you (as a normal user) can control things that you normally need extra permission for, but whatever that tricky thing is doesn't work from cron. – Greg Hewgill Sep 3 '14 at 0:03
Unfortunately no. Though it did inexplicably disable the adapter altogether. Okay after restart. I have to go now - I'll just have to go another day with a probable disconnect while I'm gone. – Dylan Sep 3 '14 at 0:33
Another potential reason for it dying in cron is that you may need to do something like the following to get it to display: */3 * * * * export DISPLAY=:0 && /path/to/your/script.sh. I'm surprised that calling notify-send would work without an X-session. (My expectation is it would silently fail.) – jvriesem Jun 18 at 19:26


You could ping your own router instead of "major sites", there is always a small chance the connection is keep dropping somewhere on your end instead of your ISP's domain servers or routers. As the matter of fact the script approach is excellent, keep pinging the LAN side with increasing interval and see how much time it takes for the connection to drop? If your LAN stays up longer than what you consider in-definitive, THEN only then consider pinging the WAN side. I would recommend replacing host names with IP addresses though, to repeatedly ping the countless internet routers (which should be fine) instead of any specific one internet DNS server (which might NOT be OK by the administrator)?

The fact that your internet connection is keep dropping might have to do with your scripts, your wget-to access throttled resource? Then your power management in BIOS (I am REALLY not sure how this affects your current kernel), and finally, your ISP's response to your issues. Again, not even in my waking dreams I would ever consider Wi-Fi to show me connection problems to the internet.

Connect by copper or by fiber and please repeat you post.

share|improve this answer
I should mention the reason I'm doing this. It's not because my wifi/VPN is constantly disconnecting. Rather, I like to leave my laptop on while I'm at work but sometimes it'll lose it's connection (while appearing to still be connected, but not being able to ping anything) and then not reconnect. This only happens maybe once every other day, and is trivial to fix when I'm actually at the machine, but not when I'm gone. And it'll stay down indefinitely if I don't fix it. In any case, much as I'd like to be connected by wire wifi is all that's really practical here. – Dylan Sep 3 '14 at 11:15
I see.. Did you at least try moving you laptop to a wired location and using the scripts to cycle the wired interface? Also unless you are still diagnosing I do not see the point testing IF there is a connection, just go drop it and re-connect? Are you on DHCP or on static IP (where you probably should be). Wi-Fi is bad enough, you should probably set every connection parameters your laptop needs, instead of trusting it to find them on your network. Authentication errors are sometimes just that.. cannot find a server to authenticate against, but the interface is up. – arch-abit Sep 3 '14 at 17:15
@archabit: Good point, but I think your "answer" is more of a comment than a solution to the user's question. – jvriesem Jun 18 at 19:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.