用于公司与家里无线网络切换
判断公司网络SSID=IOF-s,存在接入IOF-s,若不存在,则接入家里网络NETGEAR1506
#!/bin/bash
ssid=`iwlist wlan0 scan|grep IOF-s|gawk 'BEGIN{FS=":"}{print $2}'|sed -e 's/\"//g'`
if test -z "$ssid"
then
ssid=NETGEAR1506
echo "NETGEAR1506"
sudo sh -c 'cat /home/pi/shell_pro/wifi/NETGEAR1506 > /etc/network/interfaces'
sudo ifdown wlan0
sudo ifup wlan0
else
echo "IOF-s"
sudo sh -c 'cat /home/pi/shell_pro/wifi/IOF-s > /etc/network/interfaces'
sudo ifdown wlan0
sudo ifup wlan0
fi
echo $ssid
echo "------------------------------SUCCESSFUL---------------------------------"
ifconfig
将脚本丢进init.d以便开机启动
NETGEAR1506内容
pi@raspberrypi ~/shell_pro/wifi $ cat NETGEAR1506
auto lo
auto wlan0
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
allow-hotplug wlan0
iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet dhcp
wpa-ssid NETGEAR1506
wpa-psk yangguang
IOF-s类似,改掉wpa-ssid 和wpa-psk即可。