Speed test using shell
#!/bin/bash
## Speedtest script
## Copyright (C) 2012 Jishnu Mohan <jishnu7@gmail.com>
## Last revised 28-Nov-2012
##
## Usage: speedtest <input file> <output file>
##
## This script takes list of URLs from input text file and outputs
## speed and time it took to access each file/URL
if [ $1 ]
then
FILENAME=$1
else
echo "Usage: speedtest <input file> <output file>"
exit 0
fi
if [ $2 ]
then
OUTPUT=$2
else
OUTPUT="output"
fi
rm -f $OUTPUT
echo -e "URL\tSize(bytes)\tSpeed(bytes/s)\tTime(s)" >> $OUTPUT
counter=0
findspeed () {
local url=$1
curl -w $url'\t%{size_download}\t%{speed_download}\t%{time_total}\n' -o /dev/null -s $url >> $OUTPUT
counter=`expr $counter + 1`
echo -ne "Number of URLs tested: $counter\r"
}
while read line
do
findspeed $line
done < "$FILENAME"
column -t "$OUTPUT"
Written by Jishnu
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#