Skip to content

Instantly share code, notes, and snippets.

@izmailoff
Last active August 8, 2016 10:15
Show Gist options
  • Save izmailoff/302fe6aecc54d79cb49c to your computer and use it in GitHub Desktop.
Save izmailoff/302fe6aecc54d79cb49c to your computer and use it in GitHub Desktop.
Check webpage/API continuously for availability
#!/bin/bash
# Keep calling some API every second and check that it's working (status 200).
# If any other HTTP status is received print an error.
#
# Useful for observing server downtime and such.
while true
do
status="$(curl -sL -w '%{http_code}' https://api.com/something -o /dev/null)"
if [ "200" != "$status" ]
then echo "FAILED with "$status
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment