ping|awk not responsive

0

While trying melodyping, I noticed that

ping <host> |awk '{print $1}'

takes about 30 seconds until the first line is actually displayed. Even though w/o piping to awk each ping is returned in about 35 msec.

What causes that delay?

DerMike

Posted 2012-04-18T10:44:37.047

Reputation: 779

Works fine for me. What do you get after 30 seconds? – Eran Ben-Natan – 2012-04-18T11:33:57.830

@EranBen-Natan After those 30s I get a bulk of expected output, i. e. lines from ping with times around 35ms. – DerMike – 2012-04-18T12:28:52.533

Answers

3

Try this instead ;)

while true; do ping -c 1 <host> | awk '{print $1}'; done

Must be something about how ping terminates lines.

Der Hochstapler

Posted 2012-04-18T10:44:37.047

Reputation: 77 228

2Or possibly a lack of flushing. (which is just unhygienic imo) – Eroen – 2012-04-18T10:58:38.167

Nice work around. +1 – DerMike – 2012-04-18T12:30:21.410