LinHES Forums
http://forums.linhes.org/

Script an unreliable wireless connection
http://forums.linhes.org/viewtopic.php?f=24&t=21606
Page 1 of 1

Author:  manicmike [ Tue Sep 14, 2010 2:47 am ]
Post subject:  Script an unreliable wireless connection

Hi all,

Here is a script I use to automatically (re)connect to my wireless network. Anything in angled brackets should be replaced with the value of course:

1. Save the following as /usr/local/bin/checkwireless.sh

Code:
#!/bin/bash
echo "Check essid..."
if [ `iwconfig wlan0|grep ESSID|awk -F: '{print $2}'` = "\"<your_ESSID>\"" ]
then
   echo "essid has been set"
else
   echo "essid has not been set. Setting..."
   sleep 1
   iwconfig wlan0 key restricted <your-network-pass>
   iwconfig wlan0 essid "<your_ESSID>"
   sleep 1
   echo "done."
fi
# next line assumes you have a 192.168 internal address, hence 168
if [ `ifconfig wlan0|grep 168|wc -l` -eq 1 ]
then
   echo "ip address already set. Skipping."
else
   echo "ip address for wlan0 not set. Setting manually ..."
   ifconfig wlan0 192.168.<your-IP>
   sleep 1
   route add default gw 192.168.<default-gateway>
   echo "done."
fi
if [ `grep name /etc/resolv.conf|wc -l` -eq 1 ]
then
        echo "nameserver already set. Skipping"
else
   echo "nameserver not set. Setting now"
        echo 'nameserver 192.168.<your-nameserver>' > /etc/resolv.conf
fi


To get this working, I added it to root's crontab. As root, type "crontab -e", then add this:
Code:
* * * * * /usr/local/bin/checkwireless.sh 1>/var/log/wireless.log


This will check every minute. If your wireless isn't as unreliable as mine, change the first * (minutes) to something like a number between 0 and 59 (hourly, at whatever past) or */4 (etc.) for every 4 minutes, starting on the hour.

Author:  larrybpsu [ Tue Sep 14, 2010 9:25 pm ]
Post subject: 

mike...

If this wireless problem is because of an unstable router, I'd suggest that you tear it apart and see if the Caps are going bad.

I purchased a Netgear DG834G DSL Modem/Wireless/Router, and was having trouble keeping an 11mb wireless connection going. It would drop to 2mb, then 5mb, then 1mb then 11mb and it would drop the connection on a regular basis. I decided to open it up and the caps were bulging...so I replaced them, and I haven't had any trouble since! :)

I have about 15 wireless devices on my home net, so it was causing me some major grief. After changing the caps, everything is happy and ON-LINE at high speed!

Author:  manicmike [ Tue Sep 14, 2010 11:12 pm ]
Post subject: 

larrybpsu wrote:
If this wireless problem is because of an unstable router, I'd suggest that you tear it apart and see if the Caps are going bad.

Thanks but it's been like that since new (opened the shrink wrap less than 6 months ago). The wireless bridge I had before was a lot more reliable, but unencrypted and therefore ended up quite expensive (damned freeloading neighbours). I'm sure it's a compatibility thing: My Google phone works brilliantly with the router at full speed and from much further away than the Dragon is.

The script actually works quite well, so as a geek diagnosing and solving (well, working around) the problem was a good way to spend a few hours.

Mike

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/