Average website response time bash script

Ok i make a little bash script to test a particular website response time. This is done via the command line through a bash script. Anyway, here’s the script code.


#!/bin/bash

CURL="/usr/bin/curl"
echo -n "Please pass the url you want to measure: "
read url
URL="$url"
count=1;
total_connect=0
total_start=0 
total_time=0
        echo " Time_Connect Time_startTransfer Time_total ";
while [ $count -le 100 ]
do
        result=`$CURL -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} $URL`
        echo $result;

        var=$(echo $result | awk -F":" '{print $1, $2, $3}')
        set -- $var

        total_connect=`echo "scale=2; $total_connect + $1"  | bc`;
        total_start=`echo "scale=2; $total_start + $2" | bc`;
        total_time=`echo "scale=2; $total_time + $3" | bc`;
        count=$((count+1))
done
echo "average time connect: `echo "scale=2; $total_connect/100" | bc`";
echo "average time start: `echo "scale=2; $total_start/100" | bc`";
echo "average time taken: `echo "scale=2; $total_time/100" | bc`";

What the above does is to prompt you for a url to test and run it for 100 times on your machine and print out the average response time from the website server to your machine.

Assuming you save the above file in ‘shell’, you will call the above script via ‘bash ./shell’ and it will prompt you for an url and start executing the url for 100 times and gives you an average response time.

P.S: the above script required you to install bc, you can install via yum install bc or sudo apt-get install bc icon wink Average website response time bash script

 

Like this post? Share it!

digg 48 Average website response time bash script reddit 48 Average website response time bash script stumbleupon 48 Average website response time bash script delicious 48 Average website response time bash script furl 48 Average website response time bash script technorati 48 Average website response time bash script google 48 Average website response time bash script myspace 48 Average website response time bash script facebook 48 Average website response time bash script twitter 48 Average website response time bash script
share save 171 16 Average website response time bash script

No related posts.

About Clay

I am Clay who is the main writer for this website. I own a small web hosting company in Malaysia and i'm available to be hired as individual contractor on elance or odesk. You can find me on twitter.
This entry was posted in Informative, Tools and tagged . Bookmark the permalink.

Comments are closed.