我的连接不稳定,但是我有一个备份。我制作了一些 bash 脚本来检查连接并在当前连接已死时更改连接。请帮助我改进它们。
这些脚本几乎可以工作,除了没有等待足够长的时间来接收 IP(它循环到直到循环中的下一步太快)。开始:
#!/bin/bash
# Invoke this script with paths to your connection specific scripts, for example
# ./gotnet.sh ./connection.sh ./connection2.sh
until [ -z "$1" ] # Try different connections until we are online...
do
if eval "ping -c 1 google.com"
then
echo "we are online!" && break
else
$1 # Runs (next) connection-script.
echo
fi
shift
done
echo # Extra line feed.
exit 0
这是从属脚本的示例:
#!/bin/bash
ifconfig wlan0 down
ifconfig wlan0 up
iwconfig wlan0 key 1234567890
iwconfig wlan0 essid example
sleep 1
dhclient -1 -nw wlan0
sleep 3
exit 0