Created
January 9, 2018 09:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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