Skip to content

Instantly share code, notes, and snippets.

@beporter
Last active August 29, 2015 14:08
Show Gist options
  • Save beporter/981fef18dc4a46314f64 to your computer and use it in GitHub Desktop.
Save beporter/981fef18dc4a46314f64 to your computer and use it in GitHub Desktop.
Monitor a URL for HTTP 500 errors using a crude shell script.
#!/usr/bin/env bash
#
# Takes a URL as an argument. Will test that URL every X seconds for a
# 500 response code. If a 500 is returned, this script will ring the
# terminal's bell and print a message.
#
# Ref: http://beerpla.net/2010/06/10/how-to-display-just-the-http-response-code-in-cli-curl/
#
# Usage: ./monitor-500.sh "http://yoursite.com/your/page.html"
#
# Brian Porter <beporter@users.sourceforge.net>
# 2014-10-24
URL=${1:-http://google.com/}
DELAY=30
MAX=100000
for (( i=1; i<=$MAX; i++ )); do
RESPONSE=$(curl -sL -w "%{http_code} %{url_effective}\\n" "$URL" -o /dev/null)
if echo $RESPONSE | grep -q '^500'; then
echo -e '\a'
echo `date '+%Y-%m-%d %H:%M:%S'`: $RESPONSE
#else
#echo 'Check clean'
fi
sleep $DELAY
done
echo "Run complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment