Check website response time with a bash command

Join me as I share a bash command script that I have written to query a website both to get some traffic to test websites and also understand the response times.

Check website response time with a bash command
Check website response time with a bash command

Recently I had to build some demos where I had websites behind Azure load balancers and I wanted to simulate some traffic, and test my configurations.  I did use Twitter to help me visit one of the websites but I wanted to test the other websites without asking to many favours of my Twitter friends.  So I came up with this bash script.  😊

What does it do?

The short story is it's a bash script that queries your website 50 times and then reports back details of the response time for each query and the average for the 50 queries.

You can use this script to query for response time or even just to simulate traffic to your website.

Bash command running
Command running

Let's break it down

Let's walk through the script though, because let's face it, there's nothing worse than finding a helpful script on the Internet and not really knowing why things are there. 👍

for i in {1..50}; do echo -n "Run # $i :: ";
This first line is looping for 50 times, you can chance the number range up or down depending on your needs.

curl -w 'Return code: %{http_code}; Bytes Received: %{size_download};
For this line the curl command is being activated to pull information and also return information, so it's being instructed to write back the HTTP code response the curl command gets and the size of download that is being performed by the curl command.

Response Time: %{time_total}\n' -m 2 -o /dev/null -s;
This line states another output you'll get from the command, response time.  And it also states the URL you are querying.  The other commands -m, -o and -s are centered around the maximum time allowed for the transfer to take place, the output file (in this example we say no output file) and also silencing the output you normally get from the curl command.

done|tee /dev/tty|awk '{ sum+= $NF; n++ } END { if (n > 0) print "Average Response time =",sum / n; }'
The last line is wrapping things up for the script.  It's calculating and printing out the Average Response Time for the 50 queries that have just been run.