Last active
August 29, 2015 14:01
-
-
Save jasontbradshaw/7b39aff16a84a45a478e to your computer and use it in GitHub Desktop.
Given a series of URLs, tests them for a success response. Exits success only when all pass.
This file contains hidden or 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 sh | |
# handy colors, for readability | |
black='\033[0;30m' | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[0;33m' | |
blue='\033[0;34m' | |
purple='\033[0;35m' | |
cyan='\033[0;36m' | |
white='\033[0;37m' | |
color_reset='\033[0m' | |
# the URLs we want to test. these must respond to a HEAD request! if they | |
# respond to a HEAD request with success whether working or not, this test will | |
# tell you nothing of value. | |
urls=( | |
'http://www.google.com' | |
) | |
failed=0 | |
echo "Testing ${cyan}${#urls[@]}${color_reset} URLS..." | |
echo | |
for url in "${urls[@]}"; do | |
echo "Testing ${cyan}${url}${color_reset}..." | |
curl --fail --head "${url}" | |
if [ "$?" != "0" ]; then | |
echo | |
echo "[${red}FAILURE${color_reset}] for ${cyan}${url}${color_reset}" | |
failed=1 | |
else | |
echo "[${green}SUCCESS${color_reset}]" | |
fi | |
echo | |
done | |
if [ "${failed}" == "0" ]; then | |
echo "All URLs responded successfully!" | |
else | |
echo "Some URLs failed to respond with success ${yellow}:(${color_reset}" | |
fi | |
# if any of the requests failed, fail the test | |
exit $failed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment