#!/bin/bash#设置环境变量PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"export PATHwhile getopts "c:i:" opt; do case $opt in c) count=$OPTARG ;; i) ips=$OPTARG ;; \?) ;; esacdonetmp_fifofile="/tmp/ping.fifo"mkfifo $tmp_fifofileexec 6<>$tmp_fifofilerm $tmp_fifofilefor ((i=0;i<20;i++));do echodone >&6for ip in `echo $ips |awk -F'|' '{ for(i=1;i<=NF;i++) {print $i} }'`doread -u 6{ rtt=`ping -c $count $ip |grep rtt |awk '{print $4}' |awk -F'/' '{print $2}'` rtt=${rtt:-'-1'} echo $ip $rtt}&echo >&6donewaitexec 6>&-
执行效果:
[root@localhost ~]# ./weifengcli_ping -c 4 -i 192.168.4.4192.168.4.4 5.867