3

I am looking for something which shows me the missing ICMP package when running ping command or which can display failed in the output. Example below

Current output where we are missing the icmp_seq count.

64 bytes from 192.168.56.11: icmp_seq=38 ttl=64 time=1.23 ms
64 bytes from 192.168.56.11: icmp_seq=52 ttl=64 time=0.831 ms
64 bytes from 192.168.56.11: icmp_seq=53 ttl=64 time=0.679 ms
64 bytes from 192.168.56.11: icmp_seq=54 ttl=64 time=0.679 ms
64 bytes from 192.168.56.11: icmp_seq=55 ttl=64 time=0.679 ms
64 bytes from 192.168.56.11: icmp_seq=56 ttl=64 time=0.679 ms

Desired Output which will count the icmp_seq if missing then show error

64 bytes from 192.168.56.11: icmp_seq=51 ttl=64 time=1.23 ms
64 bytes from 192.168.56.11: icmp_seq=52 ttl=64 time=0.831 ms
64 bytes from 192.168.56.11: icmp_seq=53 ttl=64 time=0.679 ms
Failed
Failed
Failed 
Failed
64 bytes from 192.168.56.11: icmp_seq=58 ttl=64 time=0.679 ms
64 bytes from 192.168.56.11: icmp_seq=59 ttl=64 time=0.679 ms
Failed
Failed
Failed
0

The trick you could use is to create a loop to run the ping command with the option -c to send only 1 packet:

 while : ; do 
    ping -c1 -w1 192.168.56.11 | sed -n '/^64 bytes/p;/0 received/s/.*/Failed/p'
 done

The -w is specifying the timeout in second that will be triggered in case of host unreachable.

The sed command prints the ping output in case of success, and replace the ping output by Failed in case of failure.

0

check this code

this just parse the ping output

bash-4.1$ cat ping.awk
#!/usr/bin/awk -f
#
# analyzes ping output on Linux and looks for missed returns
# based on icmp_seq
#
# ping output is expected on stdin
#

BEGIN { num = 0 }
$5 ~ /icmp_seq=/ {
    split($5, res, /=/);
    if (res[2] != num + 1) {
        print "missed between", num, "and", res[2] }
    num = res[2];
}


bash-4.1$ cat ping_result.txt
64 bytes from 192.168.56.11: icmp_seq=38 ttl=64 time=1.23 ms
64 bytes from 192.168.56.11: icmp_seq=52 ttl=64 time=0.831 ms
64 bytes from 192.168.56.11: icmp_seq=53 ttl=64 time=0.679 ms


bash-4.1$ awk -f ping.awk ping_result.txt
missed between 0 and 38
missed between 38 and 52
  • Can you provide more information on how to use this script . – Mongrel Dec 9 '16 at 9:24
  • check the modified answer – Kamaraj Dec 9 '16 at 9:28
  • Seems that I need to run the ping 192.168.56.11 and capture the log then I need to run the above script which will calculate the output am I right. – Mongrel Dec 9 '16 at 9:38
  • yes.. you are correct – Kamaraj Dec 9 '16 at 9:41
  • I will be having atleast 14 screen which will be monitored & We need real time ping failed – Mongrel Dec 9 '16 at 9:49
0

So far I have managed to write the below command. I can run it in background & tailf the file which is getting created.

[root@connect ~]# touch result.txt; while true; do ping  -c 1 -w 2 192.168.56.11 || echo “`date` ping faild” >> result.txt; sleep 1; done
0

On Linux, could use:

fping -l google.com

The above command will show statistics:

  • Average elapsed time for each request.
  • Percentage of package lost overall.

Sample output

google.com : [160], 84 bytes, 32.0 ms (39.1 avg, 0% loss)
google.com : [161], 84 bytes, 32.3 ms (39.1 avg, 0% loss)
google.com : [162], 84 bytes, 33.8 ms (39.1 avg, 0% loss)
google.com : [163], 84 bytes, 31.3 ms (39.0 avg, 0% loss)
google.com : [164], 84 bytes, 32.8 ms (39.0 avg, 0% loss)
google.com : [165], 84 bytes, 37.3 ms (39.0 avg, 0% loss)
google.com : [166], 84 bytes, 32.4 ms (38.9 avg, 0% loss)
google.com : [167], 84 bytes, 36.1 ms (38.9 avg, 0% loss)
google.com : [168], 84 bytes, 32.8 ms (38.9 avg, 0% loss)
google.com : [169], 84 bytes, 33.8 ms (38.8 avg, 0% loss)
google.com : [170], 84 bytes, 32.6 ms (38.8 avg, 0% loss)
google.com : [171], 84 bytes, 33.0 ms (38.8 avg, 0% loss)
google.com : [172], 84 bytes, 33.2 ms (38.7 avg, 0% loss)
^C
google.com : xmt/rcv/%loss = 173/173/0%, min/avg/max = 31.3/38.7/261

Tips:

  • ctrl + c to stop it, and it will show an additional line of statistics, include:
    package sent / package received / lost percentage, min/avg/max of elapse time.

Install

It's not installed by default, could install it via:

  • Ubuntu / Mint
    sudo apt install fping

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.