脚本文件如下:
#!/bin/bash
#Author:Mr.Ding
#Created Time:2018-08-26 07:23:44
#Name:ping.sh
#Description:
shibai="/root/scripts/shell/ping_shibai.txt"
yanchigao="/root/scripts/shell/yanchigao.txt"
. /etc/init.d/functions
for i in `cat IP_list`
do
ping=`ping -c 1 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
Avg="$i 平均延迟(ms):`ping $i -c 3 |grep avg | gawk -F / '{print $5}'`"
num=`ping $i -c 3 |grep avg | gawk -F / '{print $5}'|gawk -F . '{print $1}'`
if [ $ping -eq 100 ];then
action " ping $i faild" /bin/false >>$shibai
echo "$Avg"
else
action " ping $i ok" /bin/true
echo "$Avg"
if [ $num -ge 1 ];then
<