Created
May 9, 2012 15:29
-
-
Save drewfradette/2645538 to your computer and use it in GitHub Desktop.
cURL Benchmark
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 | |
# Filename benchmark | |
# Description execute a program periodically,showing fullscreen, colored output | |
# Author Drew Fradette <http://www.github.com/drewfradette> | |
# Last Updated 2012-05-08 | |
# Usage benchmark example.com | |
# bash_version 4.2.10(1)-release | |
####################################################### | |
help() { | |
printf "Usage: ${0} example.com" | |
printf " -h\tShow the help screen." | |
printf " -c\tSet a cookie" | |
} | |
CURL=`which curl` | |
if [[ $? != 0 ]]; then | |
printf "ERROR: cURL not found" | |
exit 1 | |
fi | |
COOKIE='' | |
while getopts "hc:" OPTION; do | |
case $OPTION in | |
h) help; exit;; | |
c) COOKIE="$OPTARG";; | |
*) echo "Bad parameter"; exit 2;; | |
esac | |
done | |
# Assume the rest of the arguments are the URL to cURL | |
shift $((OPTIND-1)) | |
URL="$@" | |
# Construct a message using the cURL fields. | |
MESSAGE="\e[1;32mINFO\e[0m\n" | |
MESSAGE="${MESSAGE} \e[1;37mURL:\e[0m $URL\n" | |
MESSAGE="${MESSAGE} \e[1;37mCONTENT TYPE:\e[0m %{content_type}\n" | |
MESSAGE="${MESSAGE} \e[1;37mDOWNLOADED:\e[0m %{size_download}B (At %{speed_download}B/s)\n" | |
MESSAGE="${MESSAGE} \e[1;37mRESPONSE:\e[0m %{http_code}\n" | |
if [[ $COOKIE != '' ]]; then | |
MESSAGE="${MESSAGE} \e[1;37mCOOKIE:\e[0m ${COOKIE}\n" | |
fi | |
MESSAGE="${MESSAGE}\n" | |
MESSAGE="${MESSAGE}\e[1;32mSTATS (in Seconds)\e[0m\n" | |
MESSAGE="${MESSAGE} \e[1;37mLOOKUP:\e[0m %{time_namelookup}\n" | |
MESSAGE="${MESSAGE} \e[1;37mREDIRECT:\e[0m %{time_redirect}\n" | |
MESSAGE="${MESSAGE} \e[1;37mCONNECT:\e[0m %{time_connect}\n" | |
MESSAGE="${MESSAGE} \e[1;37mCONNECT (SSL):\e[0m %{time_appconnect}\n" | |
MESSAGE="${MESSAGE} \e[1;37mTRANSFER (BEFORE):\e[0m %{time_pretransfer}\n" | |
MESSAGE="${MESSAGE} \e[1;37mTRANSFER (START):\e[0m %{time_starttransfer}\n" | |
MESSAGE="${MESSAGE} \e[1;36mTOTAL:\e[0m %{time_total}\n" | |
MESSAGE="${MESSAGE}\n" | |
# Capture the output for the cURL | |
OUTPUT=$($CURL -s -o /dev/null -H "Cookie: ${COOKIE}" -w "${MESSAGE}" "$URL") | |
printf "$OUTPUT\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment