Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make http requests to the given url in loop
#!/bin/bash
COLOR_NC='\e[0m' # No Color
COLOR_LIGHT_RED='\e[1;31m'
COLOR_LIGHT_GREEN='\e[1;32m'
COLOR_LIGHT_YELLOW='\e[1;33m'
COLOR_LIGHT_BLUE='\e[1;34m'
usage() {
echo "$0 [options] url"
echo ""
echo "Make http requests to the given url in loop"
echo ""
echo "Options:"
echo "-h, --help show this help"
echo "-n, --number number of itterations. default is 100"
}
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-n|--number)
shift
NUMBER=$1
shift
;;
*)
break
;;
esac
done
if [ $# -ne 1 ]; then
usage
exit 1
fi
for i in `seq 1 ${NUMBER:-100}`; do
RESPONSE=`curl -s -L -o /dev/null -w "%{http_code} %{url_effective} %{time_total}" $1`
STATUS=${RESPONSE%% *}
MESSAGE=${RESPONSE#* }
if [ "$STATUS" -ge "500" ]; then
STATUS_COLOR=${COLOR_LIGHT_RED}
elif [ "$STATUS" -ge "400" ]; then
STATUS_COLOR=${COLOR_LIGHT_YELLOW}
elif [ "$STATUS" -ge "300" ]; then
STATUS_COLOR=${COLOR_LIGHT_BLUE}
elif [ "$STATUS" -ge "200" ]; then
STATUS_COLOR=${COLOR_LIGHT_GREEN}
fi
echo -e "${STATUS_COLOR}${STATUS}${COLOR_NC} ${MESSAGE}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.