This script solves some problems in wireless networks that lose connection. It's tested in Slackware 13.37 and 14. It uses wpa_supplicant and works with multiple SSID and multiple IP configuration, checks wifi status every 5 seconds and resets wireless system if not working. Wireless configuration is stored in a text file named "wifi.conf", you can define from 1 to 3 SSID with static IP or DHCP. This is a typical wifi.conf file:

ESSID[1]=office
USER[1]=job_user
PASS[1]=job_pass
CRYPT[1]=radius
PRIORITY[1]=5
HIDDEN[1]=yes
DHCP[1]=no
 
ESSID[2]=myhome
USER[2]=null
PASS[2]=my_password
CRYPT[2]=wpa
PRIORITY[2]=3
HIDDEN[2]=no
DHCP[2]=yes
 
ESSID[3]=mybar
USER[3]=null
PASS[3]=bar_password
CRYPT[3]=wpa
PRIORITY[3]=1
HIDDEN[3]=no
DHCP[3]=yes
 
ETH=eth0
 
WLAN=wlan0
 
IP=192.168.0.20
MK=255.255.255.0
GW=192.168.0.254
DNS=8.8.8.8
 
PING_TEST=yes

Make "/root/wifi" directory, then copy and paste the sorce code in a file named "wifi-connect.sh". Put this file and the file "wifi.conf" into /root/wifi/ folder.

wifi-connect.sh revision 0.9, 2017-06-18
the script now use ethtool eth0 | grep "Link detected" becouse sys-->operstate not works fine :(
wifi-connect.sh revision 0.8 - 2014-04-24
added automatic switch wlan<->eth
added 1 second delay after kill wpa_supplicant (patch reconnection problems)

To start the script in background in Slackware, add this code to /etc/rc.d/rc.local

#wlan connect
if [ -x /root/wifi/wifi-connect.sh ]; then
        /root/wifi/wifi-connect.sh &
fi

Note: to avoid software interference, disable any wireless daemon as example wicd or wifi-manager.

This software is relased "as is", without any warranty, use at own risk.

Obtida de "http://www.zoros.org/wiki/index.php?title=A_bash_script_to_recover_wifi_connection_that_often_dissociates,_loses_the_gateway,_and_other_problems._Works_with_multiple_ssid,_also"