iperf3 结果在日志文件中看起来应该不错

iperf3 结果在日志文件中看起来应该不错

我有这个结果:

Wed Aug 15 19:35:11 CEST 2018
Connecting to host x.x.x.x, port 5201
[  4] local x.x.x.x port 48944 connected to x.x.x.x port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   375 MBytes  3.14 Gbits/sec  273    471 KBytes
[  4]   1.00-2.00   sec   428 MBytes  3.59 Gbits/sec  145    376 KBytes
[  4]   2.00-3.00   sec   360 MBytes  3.02 Gbits/sec  148    454 KBytes
[  4]   3.00-4.00   sec   339 MBytes  2.84 Gbits/sec   83    407 KBytes
[  4]   4.00-5.00   sec   305 MBytes  2.56 Gbits/sec  104    414 KBytes
[  4]   5.00-6.00   sec   301 MBytes  2.53 Gbits/sec  186    440 KBytes
[  4]   6.00-7.00   sec   325 MBytes  2.73 Gbits/sec  174    485 KBytes
[  4]   7.00-8.00   sec   434 MBytes  3.64 Gbits/sec   81    677 KBytes
[  4]   8.00-9.00   sec   412 MBytes  3.46 Gbits/sec  226    537 KBytes
[  4]   9.00-10.00  sec   409 MBytes  3.43 Gbits/sec   47    372 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  3.60 GBytes  3.09 Gbits/sec  1467             sender
[  4]   0.00-10.00  sec  3.60 GBytes  3.09 Gbits/sec                      receiver

我只想要这样的一行:-)

17-08-15 19:35:11 0.00-10.00  sec  3.60 GBytes  3.09 Gbits/sec  1467

这怎么可能?

我已经开始这样的脚本,但我认为我应该使用 awk、cut 等。

host=x.x.x.x
log=/data/div/sh/iperf.log
logr=reverseiperf.log
runs=2

for run in $(seq 1 $runs); do
    date >> $log && iperf3 -c $host >> $log
done

答案1

这不是最简单的方法,但希望向您展示“一种方法”:

$ printf "%s%s\n" \
   "$(TZ=CEST date -d "$(head -1 iperf.txt)" "+%y-%m-%d %H:%M:%S")" \
   "$(grep sender iperf.txt | awk -F"]  " '{print $2}')"
18-08-15 19:35:11 0.00-10.00  sec  3.60 GBytes  3.09 Gbits/sec  1467             sender

其工作原理如下:

  • printf "%s%s\n"iperf.txt- 打印我们将从您的输出中解析的 2 个字符串
  • "$(TZ=CEST date -d "$(head -1 iperf.txt)" "+%y-%m-%d %H:%M:%S")"iperf.txt- 解析( )中的第一行head -1并将其传递给date命令,并按照示例所示的格式重新格式化日期
  • "$(grep sender iperf.txt | awk -F"] " '{print $2}')"- 解析包含字符串的行sender,然后在字符上分割该行,打印分割的参数]的右侧。]这个结果就是$2.

相关内容