自動重啓網卡(網卡不穩,常常掉線)
如上述代碼所示,假如三次均不能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