Lubos Rendek

The only solution is determination.

Simple Way to Get an Average Internet Connection Speed With Bash

| Comments

Here is a simple way to get an average Internet connection speed over a given period of time. For example I would like to test my Internet connection speed every 10 minutes, log the result and calculate average. First run test ( ask you Internet provide to provide you with a local download file.

1
$ for i in $( seq 1 100); do wget http://www.tpg.com.au/downloads/tpgspeedtest.rar &>> download.txt; sleep 600; done

The above will run test 100 times every 10 minutes. It will take 16.6667 hours to complete. As my download file is approximately 8MB in size the whole test will eat up about 800MB.

Once the test is complete we can see download speed of each test with:

1
2
3
4
5
$ grep saved download.txt
2014-06-12 19:56:06 (306 KB/s) - ‘tpgspeedtest.rar.3’ saved [9096028/9096028]
2014-06-12 19:57:26 (320 KB/s) - ‘tpgspeedtest.rar.4’ saved [9096028/9096028]
...
...

From here we can also calculate average download speed.

1
2
$ grep saved download.txt | awk '{ print $3;}'  | sed 's/(//' | awk '{ t += $1; i++ } END { print t/i}'
313

Comments