Piping twice the ping command
I am trying to pipe the output from ping twice but I do not get any output in the end.
For example if I pipe ping once as such below there is no problem. >ping 127.0.0.1 | grep ttl 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.060 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.065 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.052 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.067 ms Now trouble starts when I try to pipe this output once more like this: >ping 127.0.0.1 | grep ttl | awk '{print $7}' This does not return anything. Does anyone have an explanation? Is it something to do with eof of stdout? How can I work this around to get the expected result? I am basically trying to extract the time value to stdout. |
Are you sure, because it works for me:
Code:
bash-3.1$ ping -c 5 127.0.0.1 | grep ttl | awk '{ print $7 }' |
The output is buffered and the pipe does not return anything until the buffer is flushed or the command is terminated, as in H_TeXMeX_H's example. You can try:
Code:
ping 127.0.0.1 | grep --line-buffered ttl | awk '{print $7}' |
It works for me as well once the "-c 5" added.
However I want to avoid this option since in this case I am only getting the result once the 5 pings are done. I need to see the result as it is pinging. A sort of real time monitoring. Edit. That's the --line-buffered option that I needed. Cheers |
All times are GMT -5. The time now is 05:25 AM. |