Skip to content

Instantly share code, notes, and snippets.

@charz
Last active February 9, 2021 07:42
Show Gist options
  • Save charz/d4dee6874ebebd4d86fe90b4c4d10cbb to your computer and use it in GitHub Desktop.
Save charz/d4dee6874ebebd4d86fe90b4c4d10cbb to your computer and use it in GitHub Desktop.
curl with xid and time
#!/bin/bash
curlxidheaders() {
echo "number,timestamp,status_code,message,size,speed_bytes_per_sec,time_total,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer"
}
curlxid() {
curl -w 'code: %{http_code} %{http_connect}|size: %{size_download}|speed: %{speed_download}|total: %{time_total}, %{time_namelookup}, %{time_connect}, %{time_appconnect}, %{time_pretransfer}, %{time_redirect},%{time_starttransfer}' \
-s -o /dev/null -v "$@" 2>&1 | \
grep -E 'X-Trans-Id|total|Date:' | \
tr '\r\n<' '|' | \
awk -F '[|]' '{split($2,x,": "); split($5,d,", "); split($7,c,": "); split($8,s,":"); split($9,p, ":"); split($10,t,":"); print ", "d[2]", "c[2]", X-Trans-Id="x[2]","s[2]","p[2]","t[2]}'
}
curlxid5() {
for _ in {1..4};
do
(curlxid "$@" &) 2> /dev/null
done
(curlxid "$@") 2> /dev/null
}
curlxid10() {
for _ in {1..9};
do
(curlxid "$@" &) 2> /dev/null
done
(curlxid "$@") 2> /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment