树莓派(Raspberry Pi)USB无线网卡自动连接

Raspberry Pi 使用USB无线网卡的时候不会因为路由重启而掉线。

#!/bin/bash
while true ; do
    if ifconfig wlan0 | grep -q "inet addr:" ; then
	      sleep 60
	   else
	      echo "Network connection down! Attempting reconnection."
	      ifup --force wlan0
	      sleep 10
	   fi
done
	---------------------------邪恶的分割线-------------------------
#!/bin/bash
if ifconfig wlan0 | grep -q "inet addr:" ; then
	      exit
	   else
	      echo "Network connection down! Attempting reconnection."
	      ifup --force wlan0
	   fi
	#crontab -e
	#*/10 * * * * bash /home/network-monitor.sh  #每十分钟执行一次



sudo chmod +x ./network-monitor.sh
把它设置为可执行文件,使用命令可在后台运行。
sudo ./network-monitor.sh &
它会每60秒检查,如果你的无线网络具有网络连接。如果它发现它没有网络地址将尝试强制重新连接并继续这样执行,直到重新建立连接。如果你想阻止它在后台运行,首先使用以下命令.
fg
将迫使它为前台运行,然后你可以使用ctrl-c停止.
测试了它几个方面。
首先关闭我的WiFi接入点,该脚本没有检测到网络连接并开始试图强迫一个连接。几分钟后,重新建立连接供电接入点回来后。
另一个试验,我删除了MAC地址从地址列表中允许接入点的MAC地址过滤。网络连接了下来,重新启用的MAC地址和它一、两分钟后回来了。

2.WiFi_Check Script
Download the script to your RPi over the network. Example below saves the script in the /usr/local/bin directory: 
wget https://raw.github.com/dweeber/WiFi_Check/master/WiFi_Check -O /usr/local/bin/WiFi_Check
Set permissions to the file with 
chmod 0755 /usr/local/bin/WiFi_Check
Set up a Cron Entry
Example Runs the script every 5 minutes 
*/5 * * * * /usr/local/bin/WiFi_Check
Example Runs the script every 2 minutes 
*/2 * * * * /usr/local/bin/WiFi_Check
Example Runs the script every minute 
* * * * * /usr/local/bin/WiFi_Check

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值