Skip to content

Instantly share code, notes, and snippets.

@dale-c-anderson
Created November 10, 2021 00:36
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 dale-c-anderson/452b88b083efd3b841ed4669e21d3a2d to your computer and use it in GitHub Desktop.
Save dale-c-anderson/452b88b083efd3b841ed4669e21d3a2d to your computer and use it in GitHub Desktop.
curl probe
#!/bin/bash
# -------------------------------------------------------------
# Repeatedly probe a url forever with curl, only keeping the HTTP response code or the failure message from curl. Discard all other output.
# Any args passed to this script will be forwarded to the curl command as-is.
# Activity is profusely logged.
#
# Examples:
#
# Probe from the internet, limiting execution time:
# ./curl-probe.sh https://www.example.com/ --max-time 15
#
# Probe from inside the server:
# ./curl-probe.sh https://www.example.com/ --resolve www.example.com:443:127.0.0.1
#
# Send all probe output (stdout + stderr) to a log file:
# ./curl-probe.sh https://www.example.com/ > ./curl.log 2>&1
# -------------------------------------------------------------
ARGS=$*
if [ -z "$ARGS" ]; then
>&2 echo "Which URL do you want to probe?"
exit 1
fi
while true; do
echo ''
echo -n "BEGIN "
/bin/date --iso-8601=seconds;
(set -x && /usr/bin/time --format "COMMAND_TIME\t%E" -- /usr/bin/curl -sS -w '%{http_code}\n' "$@" -o /dev/null);
echo -n "END "
/bin/date --iso-8601=seconds;
/bin/sleep 3;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment