自动重启网卡
自动重启网卡(网卡不稳,常常掉线)
如上述代码所示,假如三次均不能ping
通某个IP地址(这里用的是局域网的网关),则重新启动网卡,之后休眠10秒,然后再重复。
创建sh文件:restart_net.sh
#! /bin/sh
while true; do
ping -c 3 www.baidu.com;
if [ $? -ne 0 ]; then
service network restart;
echo 'ping www.baidu.com fail. restart network done';
fi
ping -c 3 192.168.0.193;
if [ $? -ne 0 ]; then
service network restart;
echo 'ping 192.168.0.193 fail. restart network done';
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
版权声明
本文仅代表作者观点,不代表博信信息网立场。