Skip to content

Instantly share code, notes, and snippets.

@xyntrix
Last active October 14, 2019 20:40
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 xyntrix/f53f1e5beabf453038a9cd387516adc1 to your computer and use it in GitHub Desktop.
Save xyntrix/f53f1e5beabf453038a9cd387516adc1 to your computer and use it in GitHub Desktop.
cli http/https status checker
#!/bin/sh
## How many seconds to wait for poll
POLLTIME=10
## How many seconds to wait between polls
SLEEPTIME=3
## Ignore invalid tls negotiation such as invalid/expired certs
INSECURE="-k"
if [ -z "${1}" ]; then
URL="https://www.google.com"
else
URL="${1}"
fi
CURLCMD="curl -m ${POLLTIME} ${INSECURE} -s -o /dev/null -w "%{http_code},%{redirect_url}" ${URL}"
while [ 1 ]; do
echo "## $(date -u), checking: ${URL}"
HTTPCODE=$(${CURLCMD})
echo "ts: $(date -u +%s), http_code: ${HTTPCODE}"
case "${HTTPCODE}" in
200*)
echo "## $(date -u), online: ${URL}"
break
;;
301*)
echo "## $(date -u), online(redirect): ${URL}"
break
;;
esac
echo "##"
sleep ${SLEEPTIME}
done
@xyntrix
Copy link
Author

xyntrix commented Oct 14, 2019

give execute perms and drop in your path somewhere.. usage: is_it_up https://something.ltd.. bails if 200/301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment