直接上脚本
--------------------------------------------------------------------------
#vi /tmp/ping_check.sh
#!/bin/bash
IP="1.1.1.1"
PacketLoss=`ping -c 4 -w 4 1.1.1.1 | grep 'packet loss' | awk -F 'packet loss' '{print $1}' | awk '{print $NF}'|sed 's/\%//g'`
if [$Packetloss -eq 100]
then
echo "ping failed `date`" >>/tmp/ping_check_failed.log
systemctl restart network
#chmod +x ping_check.sh 赋予执行权限
#crontab -e 加入计划任务
*/20 * * * * /bin/sh /tmp/ping_check.sh 每20分钟运行一次脚本
----------------------------------------------------------------------------------