-1

I want to ping IP addresses and save only statistics and only the IP address - 0% packet loss

$ ping -s 100 -c 5 -i 1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 100(128) bytes of data.
72 bytes from 8.8.8.8: icmp_seq=1 ttl=48 (truncated)
72 bytes from 8.8.8.8: icmp_seq=2 ttl=48 (truncated)
72 bytes from 8.8.8.8: icmp_seq=3 ttl=48 (truncated)
72 bytes from 8.8.8.8: icmp_seq=4 ttl=48 (truncated)
72 bytes from 8.8.8.8: icmp_seq=5 ttl=48 (truncated)
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 50.869/51.435/51.602/0.348 ms

Can I write to log only IP address - 0% packet loss?

7
  • 3
    Sorry, what does this have to do with Ubuntu?
    – Elder Geek
    Nov 5, 2016 at 21:15
  • I have a hunch but I'm not sure what you actually mean. Could you please edit your question to clarify? Nov 7, 2016 at 18:00
  • 1
    @ElderGeek: I think OP wants to filter the output of ping in some way and save the filter result to a log file. That would be on topic here. Nov 7, 2016 at 18:00
  • @DavidFoerster I get that, but again, there is no mention of Ubuntu in the question and every network aware OS I can think of has ping.
    – Elder Geek
    Nov 7, 2016 at 18:26
  • 1
    @ElderGeek: Do you believe that the question and its answers would be different on other Linux distributions? Afaik we allow questions about issues that are the same on Ubuntu even if OP uses a different Linux distribution (or even a different Unix). Nov 7, 2016 at 18:40

1 Answer 1

2

You could simply run that ping command, and then pipe that into grep 'packet loss'|cut -f 6 This should give you the "0%" part.

I have not tested this and I'm not going into any further details since it is not strictly Ubuntu related. However, the commands I have provided should get you on the right track.

Always remember to do man <command> if something doesn't work - that will give you an explanation on how to use it properly.

You may also want to check out smokeping. It is a package that monitors latency to certain addresses and then gives you stats and a graph on a web interface. I know it's not exactly what you are asking for, but it could still be an alternate solution to the bigger problem.

1
  • Thank you very much. I have done so: grep -Eo '([0-9]{1,3})% packet loss'
    – Oleksii
    Nov 6, 2016 at 10:38

Not the answer you're looking for? Browse other questions tagged .