#this script is made for check one host,if it is unreachable,then output result of traceroute can refer to traceroute.txt file.
#want to check the result,please use "tail -n 100 traceroute.txt"
#version 2
#20170614
#!/bin/sh
while [ "1" = "1" ]
do
ping -c 1 192.168.30.21 > /dev/null
a=$?
if [ $a -eq 1 ]
then
echo $a >> ping.txt
b=$(awk 'END{print NR}' ping.txt)
if [ $b -eq 5 ]
then
date=` date +%Y%m%d-%k:%M:%S `
echo "=======start=======" >> traceroute.txt
echo $date >> traceroute.txt
traceroute 8.8.8.8 >> traceroute.txt
c=$(awk 'END{print NR}' traceroute.txt)
if [ $c -gt 3000 ]
then
tail -n 300 > traceroute-temp.txt
cat traceroute-temp.txt > traceroute.txt
rm -rf traceroute-temp.txt
fi
fi
else
cat /dev/null > ping.txt
fi
done
脚本说明:ping检测到ip192.168.30.21,连续不通5次就输出traceroute 8.8.8.8的结果到traceroute.txt