I have an updated fix for this issue using a startup script to connect and a time scheduled script for checking the connection, rather than having one constantly running in the background, avalible here – http://alexsleat.co.uk/2011/01/09/a-more-elegant-solution-to-ubuntu-wi-fi-reconnecting-issue/
I’ve been having some trouble with my wifi on Ubuntu recently but I think it’s because I’m almost out of range of the access point. The problem is that once it disconnects it never seems to be able to reconnect unless wireless is disabled and re-enabled. No doubt there is another way of fixing this issue but it gives me a chance to write my first shell script.
In short the script disables network-manager (it was trying to do things auto which was screwing with things), sets up the connection and connects then checks for a string in the wireless card parameters which will only occur if it’s disconnected, if the string appears it’ll disable and re-enable the wireless device which seems to allow it to connect again. If it’s connected it’ll wait 3 minutes (180 seconds) before checking again where as if it does disconnect it’ll check again 30 seconds after it’s tired rebooting the device.
Here’s the script, be sure to try it if you’re having the same problem (you might need to change the wireless device ‘wlan1’ to yours) and comment if I’m doing something wrong or there’s another way around this, cheers.
#!/bin/bash service network-manager stop iwconfig wlan1 essid NETWORKNAME iwconfig wlan1 key NETWORKKEY ifconfig wlan1 up dhclient3 wlan1 while true; do if (iwconfig wlan1) | grep -o "Access Point: Not-Associated" then ifconfig wlan1 down echo "not connected, rebooting Wifi" ifconfig wlan1 up sleep 30 else echo "connected" sleep 180 fi done