Skip to content

Instantly share code, notes, and snippets.

@askobara
Created September 14, 2015 13:24
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 askobara/66ff8e31093b3e1da351 to your computer and use it in GitHub Desktop.
Save askobara/66ff8e31093b3e1da351 to your computer and use it in GitHub Desktop.
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