Skip to content

Instantly share code, notes, and snippets.

@NeilMasters
Created March 20, 2023 10:15
Show Gist options
  • Save NeilMasters/517da1439328db3d390fff2645044acd to your computer and use it in GitHub Desktop.
Save NeilMasters/517da1439328db3d390fff2645044acd to your computer and use it in GitHub Desktop.
Get http statuses for a grouped list of urls
#!/bin/bash
###############################################################################
#
# Script accepts a csv of sites by named key.
#
# Usage
#
# ./benchmark-curl.sh 'group1,https://whatever,https://that,https://this
# group2,https://whatever,https://that,https://this'
#
# Output
#
# group1
# https://whatever, 200
# https://that, 200
# https://this, 200
# group2
# https://whatever, 200
# https://that, 200
# https://this, 200
#
# Tinker with the output to give you what you want
#
###############################################################################
echo
echo "Obtaining HTTP status for each site within the list"
echo
LIST=$1
IFS=$'\n' read -rd '' -a GROUPINGS <<<"$LIST"
for GROUP in "${GROUPINGS[@]}"
do
IFS=","
PARTS="$GROUP"
I=0
for SITE in $PARTS
do
if [[ $I -gt "0" ]]; then
HTTP_STATUS=$(curl -L -s -o /dev/null -w "%{http_code}" "${SITE}")
echo "$SITE,$HTTP_STATUS"
else
echo $SITE
fi
I=$((I+1))
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment