简体   繁体   English

如何减少Curl命令的output?

[英]How to reduce the output of the Curl command?

Am looking for a way to restrict the output of curl command我正在寻找一种方法来限制 curl 命令的 output

For example when using curl to check if port is open on server, just want to restrict the output to first lines to confirm that port is open例如,当使用 curl 检查服务器上的端口是否打开时,只想将 output 限制在第一行以确认端口已打开

curl -v host:1521 want to just display first 3 lines of output *About to connect to *Trying host..connected * Connected to host curl -v host:1521 只想显示 output 的前 3 行 *关于连接到 *尝试主机..已连接 *已连接到主机

Why not to pipe it to head ?为什么不把pipe给head呢?

curl -v host:1521 | head -n3

where -n3 means 3 lines from top.其中-n3表示从顶部开始的 3 行。

EDIT:编辑:

As discussed in comments you use -v option to capture headers etc. which are printed on stderr instead of stdout so head doesn't affect it.正如评论中所讨论的,您使用-v选项来捕获打印在 stderr 而不是 stdout 上的标题等,因此head不会影响它。 You have to redirect stderr to stdout and after that operate on:您必须将 stderr 重定向到 stdout 并在之后操作:

curl -v www.example.com 2>&1 | grep Connected

This will return * Connected to www.example.com (IP_ADDRESS_HERE) port 443 (#0) if connected successfully and nothing otherwise.这将返回* Connected to www.example.com (IP_ADDRESS_HERE) port 443 (#0)如果连接成功,否则没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM