Skip to content
 

Bash scripting web tests with ‘wget’

Did you know you can use the command line wget tool to perform simple tests on your web site?

In a Linux environment combining the programmatic capabilities of a Bash (Bourne Again SHell) script with wget is pretty easy and allows you to carry out basic load and performance tests. These tests could be run directly from your local machine or any other remote machine or VM with a Bash shell and wget, which is pretty much any Linux distro.

When I recently wanted to check whether a problem, where my web servers died under load, was resolved I wrote the following simple script:

#!/bin/bash
if [ $# -ne 2 ]; then  
        echo "Usage: wload URL #processes(eg. 1000)" 
        exit 
fi 
start=`date +%H:%M:%S` 
x=1
while [ $x -le $2 ]
do 
  echo "Request $x.."
  wget -o /dev/null -q -O /dev/null $1 &
  sleep 0.01
  x=$(( $x + 1 ))
done 
wait 
end=`date +%H:%M:%S` 
printf "%s " `hostname` $1 : $2 $start $end 
echo

You can save this as wload.sh and execute it in a Linux environment using the command:
./wload.sh [your URL under test] [no. concurrent requests to fire]

I think these kind of scripts are pretty neat, and I believe there is definitely a place for the ‘humble’ Bash script in the development process every now and again. You can do a lot more with Bash than just fire off requests at a page and as it is essentially a programming language it can be very powerful in the right hands.

Leave a Reply