Created
November 10, 2021 00:36
-
-
Save dale-c-anderson/452b88b083efd3b841ed4669e21d3a2d to your computer and use it in GitHub Desktop.
curl probe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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