我只尝试获取命令的前5行。通常的方法是使用head选项,但它并不适用于所有命令。下面是一些例子。
head选项适用于nping命令. rajkumar:~/automation$ nping | head -5
Nping 0.7.60 ( https://nmap.org/nping )
Usage: nping [Probe mode] [Options] {target specification}
TARGET SPECIFICATION:
Targets may be specified as hostnames, IP addresses, networks, etc.
rajkumar:~/automation$ nping | wc -l
119
rajkumar:~/automation$然而,
head选项不适用于iperf3命令,如果找不到这些参数和输出错误,则需要一些预定义的命令行参数和输出错误。如何克服这一问题? rajkumar:~/automation$ iperf3 | head -5
Usage: iperf [-s|-c host] [options]
iperf [-h|--help] [-v|--version]
Server or Client:
-p, --port # server port to listen on/connect to
>>>>>>>>>>>> TRIMMED OUTPUT <<<<<<<<<<<<<<<<<
[KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga-
iperf3 homepage at: http://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
iperf3: parameter error - must either be a client (-c) or server (-s) <<<< Error given by iperf3 command
rajkumar:~/automation$发布于 2021-09-06 13:04:55
您正在混淆stderr (标准错误)和stdout (标准输出)。
这将起作用:
iperf3 2>&1 | head -52>&1将stderr重定向到stdout。
https://stackoverflow.com/questions/69074911
复制相似问题