linux 环境 批量发送get请求
背景,此文仅用来记录一下curl批量发送get请求的命令
命令1
创建urls.txt
http://httpbin.org/delay/1?1
http://httpbin.org/delay/1?2
http://httpbin.org/delay/1?3
http://httpbin.org/delay/1?4
http://httpbin.org/delay/1?5
执行命令
cat urls.txt | xargs -P 5 -I {} sh -c 'curl -s "{}"; echo'
发送请求并显示响应状态码
cat urls.txt | xargs -P 5 -I {} sh -c 'echo "GET {}"; curl -s -w "%{http_code}" -o /dev/null "{}"; echo'
展示更详细的信息
cat urls.txt | xargs -P 5 -I {} sh -c 'echo "GET {}";curl -s -w "HTTP状态码: %{http_code}, DNS解析: %{time_namelookup}s, 建立连接: %{time_connect}s, TLS握手: %{time_appconnect}s, 首字节: %{time_starttransfer}s, 总耗时: %{time_total}s" \-o /dev/null "{}";echo
'
只看总耗时和状态码
cat urls.txt | xargs -P 5 -I {} sh -c 'printf "%-40s" "请求: {}";curl -s -w "状态码: %{http_code} | 总耗时: %{time_total}s" -o /dev/null "{}";echo
'