2

I've got a Ubuntu machine running a software that requires internet. However, sometimes the wifi fails (router reboot for example) and doesn't find the network again, until I manually service network-manager restart or I switch off and on the wifi to find it.

Is there a possible way to run a cron job or a supervisord job to monitor the connectivity and if the network can't be found to restart the network-manager service and connect to that specific SSID?

Blue Genie
  • 83
  • 6
  • 1
    FWIW I have two laptops running Ubuntu 14.04 that almost always need a `service network-manager restart` command to get WiFi working after the machine has been suspended. Replacing the AP did not solve the problem. – kasperd May 29 '15 at 05:54
  • Out od curiosity, is the SSID broadcast? I've had that problem with hidden networks. – Recct May 29 '15 at 11:25
  • @Recc I am seeing this problem on a network where the SSID is being broadcast. The old AP where I had the problem as well was also configured to broadcast the SSID. – kasperd May 29 '15 at 21:07

1 Answers1

1

Create a script that will:

  1. Check if NetworkManager reports the WiFi interface connected
  2. If it isn't, use NetworkManager to connect to the given WiFi

So no nm restart is required. In order to do the above use nmcli:

nmcli d | grep wlan0 | grep -v disconnected >/dev/null ||  nmcli c up id wifiid

To get the id run nmcli c

There might be some problems connecting - sometimes it timesout. Let us know if it works for you.

Konrad Gajewski
  • 1,518
  • 3
  • 15
  • 29
  • Thank you Konrad. I tried to run this script for a wifi id and it connected to that wireless successfully. However, my main question is how to monitor the network? From what I've found this far, I have to to create a cronjob as root running every X minutes a script with a `if ping to google not working` then `nmcli d | grep wlan0 | grep -v disconnected >/dev/null || nmcli c up id wifiid`. I don't need to `iwlist wlan0 scan` or `service network-manager restart` if I'm right. – Blue Genie May 29 '15 at 11:40
  • Well, the command I gave you verifies that the AP connection is up, and unless it is, reconnects. That was AFAIU the issue all along. There is hardly anything the Ubuntu machine can do, it the problem is elsewhere. You can run this in your cron. – Konrad Gajewski May 30 '15 at 03:44
  • Thx. (And also you might want check out scripts in /etc/network/. They get run when a interface changes state. Worth noting.) – Konrad Gajewski May 30 '15 at 14:24