Skip to content

Instantly share code, notes, and snippets.

@anapsix
Created January 9, 2018 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anapsix/67f673b36adb9f2f3cae02f39a1004a9 to your computer and use it in GitHub Desktop.
Save anapsix/67f673b36adb9f2f3cae02f39a1004a9 to your computer and use it in GitHub Desktop.
Check URL and return timing, http code, number of redirects, and effective url
#!/usr/bin/env bash
#
# returns the following
# [curl exit code],[total request time],[http response code],[number of redirects],[effective url]
#
if [[ ${1} == '' ]]; then
echo >&2 'missing URL to check'
echo >&2 "Usage: $0 google.com"
exit 1
fi
check() {
local curl_output
local curl_return
curl_output="$(curl -sL \
-o /dev/null \
--fail-early \
--max-time ${CURL_MAX_TIME:-5} \
--connect-timeout ${CURL_CONNECT_TIMEOUT:-3} \
-w "%{time_total},%{http_code},%{num_redirects},%{url_effective}\n" \
"$@")"
curl_return="$?"
echo "${curl_return},${curl_output}"
return ${curl_return}
}
check "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment