0

I want to capture all bandwidth value in iperf not only Mbits size but also bits and Kbits as well.

[3] 0.0 - 1.0 sec 128 Kbytes 1.05 Mbits/sec
[3] 1.0 - 2.0 sec 0 Kbytes 0.00 bits/sec
[3] 2.0 - 3.0 sec 90 Kbytes 900.5 Kbits/sec

So far I know about this

iperf -c 10.0.0.1 -i 1 -t 100 | grep -Po '[0-9.]*(?= Mbits/sec)'

but that only captures Mbits value. How to capture bits/sec and Kbits/sec as well at the same time with Mbits/sec?

Thank you

bnbfreak
  • 353
  • 3
  • 14

3 Answers3

1

I know this is old, but in case someone stumbles upon it, you could add an optional character class to your grep:

grep -Po '[0-9.]*(?= [KM]*bits/sec)'
0

This should do it

iperf -c 10.0.0.1 -i 1 -t 100 | awk '{print$5}' FPAT=[.0-9]+
  • FPAT=[.0-9]+ defines a field as one or more of .0-9
  • {print$5} prints just the rate
Zombo
  • 1
  • 62
  • 391
  • 407
0

you might want to man iperf to see what's supported. Here's the latest from 2.0.10

   -f, --format
          [abkmgKMG]   format to report: adaptive, bits, Kbits, Mbits, KBytes, MBytes (see NOTES for more)
rjmcmahon
  • 324
  • 1
  • 3