Skip to content

Instantly share code, notes, and snippets.

@hsiboy
Created June 3, 2014 09:53
Show Gist options
  • Save hsiboy/a3881bb7aef2843eb966 to your computer and use it in GitHub Desktop.
Save hsiboy/a3881bb7aef2843eb966 to your computer and use it in GitHub Desktop.
fetch a url a number of times, spit out csv
#!/bin/bash
echo -n "url to measure: "
read url
URL="$url"
echo -n "How many times to fetch? "
read loop
NOWD=$(date +"%Y-%m-%d")
clean_var()
{
INVAR=$1
VARLEN=${#INVAR}
VAR=$(echo -ne "$RESPONSE" | grep -m 1 "$INVAR")
VAR=${VAR:VARLEN}
# below ^M is enetered in vi/vim using ctrl+v then ctrl+M
VAR=${VAR/^M/}
VAR=${VAR/ /}
VAR=${VAR:="Nan"}
echo -n "$VAR"
}
for (( c=1; c<=$loop; c++ ))
do
NOWT=$(date +"%T")
RESPONSE=$(curl -j -D - -o /dev/null -L -A "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3" --header "X-Forwarded-For: 192.102.214.4" --connect-timeout 90 -m 120 --silent --progress-bar --write-out 'STATS%{time_namelookup},%{time_connect},%{time_starttransfer},%{time_total},%{http_code},%{size_header},%{size_download},%{speed_download},%{url_effective}' ${URL})
XHOST=`clean_var X-Host:`
XVERSION=`clean_var X-Version:`
STATS=$(echo "$RESPONSE" | grep "STATS")
STATS=${STATS:5}
printf "$NOWD,$NOWT,$XHOST,$XVERSION,$STATS,$URL\n" >> ./$NOWD.csv
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment