Skip to content

Instantly share code, notes, and snippets.

@NFarrington
Created May 25, 2019 09:50
Show Gist options
  • Save NFarrington/bf516f9890c14c0d3edd938857734ba3 to your computer and use it in GitHub Desktop.
Save NFarrington/bf516f9890c14c0d3edd938857734ba3 to your computer and use it in GitHub Desktop.
Curl Healthcheck
#!/bin/bash
# A basic healthcheck to determine when a URL is unavailable, and for how long.
[ -z "$1" ] && { echo "You must specify the URL to check" >&2; exit 1; }
URL="$1"
SLEEP="1"
CURL_CONNECT_TIMEOUT="1"
CURL_MAX_TIME="2"
while sleep "$SLEEP"; do
curl --write-out "$(date +%T) -- %{http_code} -- %{time_total}\n" --silent --connect-timeout "$CURL_CONNECT_TIMEOUT" --max-time "$CURL_MAX_TIME" --output /dev/null "$URL"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment