First, code display

#! /bin/bash ip=$* echo $ip num=`ping -c 3 ${ip}|grep icmp_seq|awk '{print $7}'|cut -d= -f2` for snum in $num do if [ `echo  "${snum}>10"|bc` -eq 1 ]; Then echo "${snum}"; fi doneCopy the code

Second, code parsing

Variable assignment

#$* displays all the arguments passed to the script in a single string, assigning the values to the variable IP IP =$*Copy the code

The core code

num=`ping -c 10 ${ip}|grep icmp_seq|awk '{print $7}'|cut -d= -f2`
Copy the code
Ping www.a.shifen.com (110.242.68.4): 56 data bytes 64 bytes from 110.242.68.4: Icmp_seq =0 TTL =49 time= 12.492 ms 64 bytes from 110.242.68.4: Icmp_seq =1 TTL =49 time=12.712 ms 64 bytes from 110.242.68.4: Icmp_seq =2 TTL =49 time= 13.138ms -- www.a.shifen.com ping statistics -- 3 packets transmitted, 3 packets received, 0.0% packet loss round - trip min/avg/Max/stddev 13.172/0.284 = 12.490/12.791 / msCopy the code
# piping line search contains icmp_seq grep icmp_seq ping - c 3 www.baidu.com | grep icmp_seq results: 64 bytes from 110.242.68.4: Icmp_seq =0 TTL =49 time=28.042 ms 64 bytes from 110.242.68.4: Icmp_seq =1 TTL =49 time=12.626 ms 64 bytes from 110.242.68.4: ICmp_seq =2 TTL =49 time=12.468 msCopy the code
# line reads the specified file, with a space as a delimiter, print the seventh field awk '{print $7}' ping - c 3 www.baidu.com | grep icmp_seq | awk '{print $7}' results: Time =13.738 time=13.246 time=13.370 # Cut -d '=' -f Ping - c 3 www.baidu.com | grep icmp_seq | awk '{print $7}' | the cut - d '=' -f 2:20.684 20.841 17.836Copy the code

To iterate over

For snum $num do # - in eq 1 is used to judge whether the output of the echo command is 1, 1, explain to true if [` echo "${snum} > 10" | BC ` - eq 1); Then echo "${snum}"; fi doneCopy the code

Three, to achieve the effect