#!/bin/bash
while :
do
#包大小
PACKETSIZE=32
#发包数
PACKETTIMES=10
#间隔时间
INTERVAL=1
#ip列表文件位置
IPFILE=/tmp/1
#多长时间测试一次(秒)
SLEEPTIME=60
#临时文件
TMP=/tmp/pingtmp
#输出的ping.txt文件路径
OUTPUT=/tmp/ping.txt
#本机IP(这都不知道自己切JJ)
HOSTIP=1.1.1.1
while read line
do
> ${TMP}
ping -c ${PACKETTIMES} -i ${INTERVAL} -s ${PACKETSIZE} $line >> ${TMP}
DELAY=`grep rtt ${TMP} | awk '{print$4}' |awk -F "/" '{print$1"/"$2"/"$3}'`
LOST=`grep loss ${TMP} |awk -F "%" '{print$1"%"}'|awk '{print $NF}' `
DATE=`date +"%Y-%m-%d %H:%M:%S"`
if [ -z "${DELAY}" ]
then
DELAY=none
fi
echo "################################################" >> ${OUTPUT}
echo "${DATE} ${HOSTIP} > ${line} the min/avg/max is ${DELAY} and packets lost ${LOST}" >> ${OUTPUT}/ping.txt
rm -rf ${TMP}
done<${IPFILE}
sleep ${SLEEPTIME}
done
while :
do
#包大小
PACKETSIZE=32
#发包数
PACKETTIMES=10
#间隔时间
INTERVAL=1
#ip列表文件位置
IPFILE=/tmp/1
#多长时间测试一次(秒)
SLEEPTIME=60
#临时文件
TMP=/tmp/pingtmp
#输出的ping.txt文件路径
OUTPUT=/tmp/ping.txt
#本机IP(这都不知道自己切JJ)
HOSTIP=1.1.1.1
while read line
do
> ${TMP}
ping -c ${PACKETTIMES} -i ${INTERVAL} -s ${PACKETSIZE} $line >> ${TMP}
DELAY=`grep rtt ${TMP} | awk '{print$4}' |awk -F "/" '{print$1"/"$2"/"$3}'`
LOST=`grep loss ${TMP} |awk -F "%" '{print$1"%"}'|awk '{print $NF}' `
DATE=`date +"%Y-%m-%d %H:%M:%S"`
if [ -z "${DELAY}" ]
then
DELAY=none
fi
echo "################################################" >> ${OUTPUT}
echo "${DATE} ${HOSTIP} > ${line} the min/avg/max is ${DELAY} and packets lost ${LOST}" >> ${OUTPUT}/ping.txt
rm -rf ${TMP}
done<${IPFILE}
sleep ${SLEEPTIME}
done