北大网关断网自动重连脚本

编写脚本autoconnect

1
2
3
4
5
6
7
8
9
#!/bin/bash
curl --connect-timeout 5 "baidu.com" > /dev/null 2>&1
if [ $? == 0 ]; then
echo "link already established."
else
echo "link lost, try reconnecting..."
connect -u ${账号} -p ${密码} > /dev/null 2>&1
echo "link established."
fi

随后赋予该脚本执行权限

1
chmod +x autoconnect

autoconnectconnect移动到/usr/local/bin目录下

1
2
mv connect /usr/local/bin
mv autoconnect /usr/local/bin