How to fetch numbers from ping result?
我在sunOS上做了一个ping实验
1 2 3 4 5 6 7 8 9 10 | PING www.google.com: 56 data bytes 64 bytes from iad23s26-in-f18.1e100.net (173.194.121.50): icmp_seq=0. time=8.72 ms 64 bytes from iad23s26-in-f18.1e100.net (173.194.121.50): icmp_seq=1. time=8.69 ms 64 bytes from iad23s26-in-f18.1e100.net (173.194.121.50): icmp_seq=2. time=8.61 ms 64 bytes from iad23s26-in-f18.1e100.net (173.194.121.50): icmp_seq=3. time=8.54 ms 64 bytes from iad23s26-in-f18.1e100.net (173.194.121.50): icmp_seq=4. time=8.62 ms ----www.google.com PING Statistics---- 5 packets transmitted, 5 packets received, 0% packet loss round-trip (ms) min/avg/max/stddev = 8.54/8.64/8.72/0.073 |
我需要的是收到的数据包数
我试图使用
我可以使用
我会带你走大部分路。
1 | ping -s www.google.com 56 5 | awk '/transmitted/ {print $1,$4,$7}; /round-trip/ {print $5}' | sed -e 's/[\/\% ]/,/g' |
这将净你:
1 2 | 5,5,0, 8.54,8.64,8.72,0.073 |
从这里你只需要将它分配给bash中的变量并按照你认为合适的方式操作它:
1 | RESULT=`ping -s www.google.com 56 5 | awk '/transmitted/ {print $1,$4,$7}; /round-trip/ {print $5}' | sed -e 's/[\/\% ]/,/g'` |