My WiFi stops working, and this script doesn't fix it

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,242
3,831
75
I have an old version of Xubuntu (16.10, I think) on my TV recording computer. It has a custom kernel I didn't want to risk upgrading.

Every so often, the WiFi on that computer goes down. It shows as no signal received. If I go to the computer and manually turn WiFi on and off, it starts working again.

So, I figured, if I write a script to do that every hour, that should fix the WiFi, right?

Script:
Code:
#!/bin/bash
if ! ping -q -t 1 -c 1 192.168.0.1 > /dev/null ; then
  nmcli radio wifi off
  sleep 15
  nmcli radio wifi on
fi

And I added to my crontab (as a regular user):
Code:
# m h  dom mon dow   command
30 * * * * /my/path/to/retry_wifi

Any idea why it doesn't work?
 

serpretetsky

Senior member
Jan 7, 2012
642
26
101
I'm not sure, but If I was debugging I would probably first test
if the script itself works without crontab. (disconnect your wifi and run the script. does it reconnect?)
 

Amol S.

Platinum Member
Mar 14, 2015
2,390
709
136
Try the following code instead.

Bash:
#!/bin/bash
if ! ping -q -t 1 -c 1 192.168.0.1 > /dev/null ; then
  sudo nmcli radio wifi off
  sleep 15
  sudo nmcli radio wifi on
fi

Maybe super user privlage is required.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,242
3,831
75
Unfortunately, this happens randomly, and most times it seems more important to me to get the WiFi working right then, with a mouse, than to get a keyboard to diagnose the problem. It did occur to me to put icons on the desktop today, so next time maybe I can figure it out.

Maybe super user privlage is required.

I also put the script in the root crontab, so maybe there won't be a next time. :)
 

Red Squirrel

No Lifer
May 24, 2003
67,342
12,099
126
www.anyf.ca
I think what happens is cron runs more in the background, you probably need something that runs more in the "foreground" (ex: equivalent to if you ran a terminal and ran it manually) not sure how to automate that though.

Wifi on Linux has always been super iffy though. I've ran into that too where it just dies for no reason and needs to be reset. One workaround might be to get a wireless bridge device that has ethernet out. Basically acts like a router that uplinks to the wifi. I've used one to provide temporary internet to a small network using hot spot on my phone.