Linux下ping指定ip,若出错自动重启网卡

脚本如下:

#!/bin/sh
if ! ping -c 5 192.168.90.1 > /dev/null 2>&1
then
echo "The network is down! Now try restarting!" |  service network restart
fi

再添加一个每分钟执行的cronjob即可。


改进写入错误时间到日志文件

#!/bin/sh
if ! ping -c 5 192.168.90.1 > /dev/null
then
echo `date` >>/home/pingtest.log
echo -e "The network is down! Now try restarting!\n" >>/home/pingtest.log
service network restart
fi


你可能感兴趣的:(linux,service,NetWork,网卡)