Skip to content

Instantly share code, notes, and snippets.

@linusfoldemo
Created December 17, 2015 07:13
Show Gist options
  • Save linusfoldemo/6c9384d8414d3d5fbdb6 to your computer and use it in GitHub Desktop.
Save linusfoldemo/6c9384d8414d3d5fbdb6 to your computer and use it in GitHub Desktop.
#!/bin/bash
URL_TO_VERIFY=$1
EXPECTED_HTTP_CODE="200"
echo "Verifying '${URL_TO_VERIFY}' on $(hostname)"
RESULT=$(wget -O/dev/null --retry-connrefused -S "${URL_TO_VERIFY}" 2>&1 | grep "HTTP/" | cut -d' ' -f4)
if [ "$?" -ne "0" ]; then
echo "Unable to connect to '${URL_TO_VERIFY}"
exit 10
fi
if [ -z ${RESULT} ] || [ "${RESULT}" -ne ${EXPECTED_HTTP_CODE} ]; then
echo "Verify '${URL_TO_VERIFY}' failed, http return code was '${RESULT}' expected '${EXPECTED_HTTP_CODE}'\n"
exit 20
fi
echo "Verified ${URL_TO_VERIFY} with success!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment