自動重啓網卡

自動重啓網卡(網卡不穩,常常掉線)

如上述代碼所示,假如三次均不能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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章