- 论坛徽章:
- 0
|
大家好,我这里想得出ping一些地址的响应值。
我自己研究了一下。写了一下下面的脚本,但是感觉得出值的时间太慢(除去ping的时间)
想请教高手优化优化,或者给些别的方法
=====================================
[root@cache /]# ping 202.96.209.6 -c 5
PING 202.96.209.6 (202.96.209.6) 56(84) bytes of data.
64 bytes from 202.96.209.6: icmp_seq=1 ttl=53 time=6.65 ms
64 bytes from 202.96.209.6: icmp_seq=2 ttl=53 time=5.88 ms
64 bytes from 202.96.209.6: icmp_seq=3 ttl=53 time=3.96 ms
64 bytes from 202.96.209.6: icmp_seq=4 ttl=53 time=4.93 ms
64 bytes from 202.96.209.6: icmp_seq=5 ttl=53 time=3.41 ms
--- 202.96.209.6 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 3.416/4.969/6.650/1.192 ms
=====================================
[root@cache /]# cat ping.sh
#!/bin/sh
conn=`ping 202.96.209.5 -c 3 |
awk '/time/{print $7}' |
sed '/packet/'d |
cut -c 6-11 |
awk 'BEGIN { a=0 }; { a=a+$0 }; END { print a/NR }'`
echo $conn
=====================================
[root@cache /]# ./ping.sh
4.56333 |
|