1、创建主机列表文件hosts.ping.lst
2、用ping命令并截取最后的ping统计结果那两行
3、输出重定向到日志文件:当日日期.ping.log
4、同时用tail -f 来查看实时的运行结果
#
!/sbin/sh
logfile =/ etc / chk / log / ` date +% Y % m % d` . ping . log
if [ - f " $logfile " ]; then
rm $logfile
fi
touch $logfile
tail - f $logfile &
for i in `cat / etc / chk / hosts . ping . lst`
do
echo $i >> $logfile
ping $i 1024 - n 3 | egrep - e " loss|avg " >> $logfile
done
kill `ps - f - u root | grep " tail -f $logfile " | awk ' {print $2} ' ` >/ dev / null
exit
logfile =/ etc / chk / log / ` date +% Y % m % d` . ping . log
if [ - f " $logfile " ]; then
rm $logfile
fi
touch $logfile
tail - f $logfile &
for i in `cat / etc / chk / hosts . ping . lst`
do
echo $i >> $logfile
ping $i 1024 - n 3 | egrep - e " loss|avg " >> $logfile
done
kill `ps - f - u root | grep " tail -f $logfile " | awk ' {print $2} ' ` >/ dev / null
exit