自动重启网卡(网卡不稳,常常掉线)
如上述代码所示,假如三次均不能ping
通某个IP地址(这里用的是局域网的网关),则重新启动网卡,之后休眠10秒,然后再重复。
创建sh文件:restart_net.sh
while true; do
ping -c 3 192.168.0.193;
if [ $? -ne 0 ]; then
ifup eth0;
fi
sleep 10;
done
执行
/bin/bash restart_net.sh 2>&1 > /root/shell/log/restart_net.log &
查看日志: tail -f /root/shell/log/restart_net.log