LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-05-2009, 09:20 AM   #1
noeldum
LQ Newbie
 
Registered: Jun 2007
Distribution: Fedora, Rhel4, Debian
Posts: 13

Rep: Reputation: 0
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.
 
Old 07-05-2009, 10:21 AM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Are you sure, because it works for me:

Code:
bash-3.1$ ping -c 5 127.0.0.1 | grep ttl | awk '{ print $7 }'
time=0.036
time=0.036
time=0.036
time=0.041
time=0.035
 
Old 07-05-2009, 10:31 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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}'
 
Old 07-05-2009, 10:39 AM   #4
noeldum
LQ Newbie
 
Registered: Jun 2007
Distribution: Fedora, Rhel4, Debian
Posts: 13

Original Poster
Rep: Reputation: 0
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

Last edited by noeldum; 07-05-2009 at 10:42 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
piping output of find to another command or loop steven19782007 Linux - Newbie 6 06-25-2009 06:29 PM
setsid and command-line piping in bash ta0kira Programming 7 04-28-2008 10:31 PM
Simple question about command syntax ping/log ping results ohalnet Linux - Networking 1 07-25-2006 05:46 AM
Piping and CP command JerryMcFarts Linux - Software 5 10-07-2005 07:21 PM
Loss of scp progress indicator when piping command to tee Arodef Linux - General 1 03-08-2005 10:01 PM


All times are GMT -5. The time now is 06:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration