Linux 常见命令 curl的高级用法---curl 格式化输出
前言
Curl 命令是在运维过程中,非常常见的命令,cURL是一个利用URL语法在命令行下工作的文件传输工具,1997年首次发行。它支持文件上传和下载,所以是综合传输工具,但按传统,习惯称cURL为下载工具。cURL还包含了用于程序开发的libcurl。
cURL支持的通信协议有FTP、FTPS、HTTP、HTTPS、TFTP、SFTP、Gopher、SCP、Telnet、DICT、FILE、LDAP、LDAPS、IMAP、POP3、SMTP和RTSP。
curl还支持SSL认证、HTTP POST、HTTP PUT、FTP上传, HTTP form based upload、proxies、HTTP/2、cookies、用户名+密码认证(Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos)、file transfer resume、proxy tunneling。
在使用时,会希望获取更多的信息,比如请求耗时,访问时延,请求大小等相关参数,虽然配合其他命令也可以实现该效果,比如time 命令配合curl命令公共使用,不过还是不够方便,可以使用curl 命令的格式化输出的功能,配置显示格式。
官文文档:
https://curl.haxx.se/docs/manpage.html
使用说明
官网解释:
实际操作:
[root@elb handle_log]# cat format_curl.txt time_namelookup: %{time_namelookup} time_connect: %{time_connect} time_appconnect: %{time_appconnect} time_pretransfer: %{time_pretransfer} time_redirect: %{time_redirect} time_starttransfer: %{time_starttransfer} ---------- time_total: %{time_total} http_code: %{http_code} ---------- local_ip: %{local_ip} size_download: %{size_download} size_header: %{size_header} size_request: %{size_request} size_upload: %{size_upload} speed_download: %{speed_download} speed_upload: %{speed_upload}[root@elb handle_log]# ls
使用测试:
curl -w "@format_curl.txt" http://XX.XX.91.152:9090/graph -o /dev/null