How to: run a speed test every hour and log it into a file on Linux

Automating speed test to diagnose any potential networking issues such as congestion or capacity has never been easier. Nowadays, there are many solutions available that can be utilized whether on your internal LAN or through the internet. The easiest way of gauging your internet connection speed would be from Here’s how you can set it up over on a Linux machine.

Speedtest CLI

Fortunately, by Ookla has a Linux version available for the shell called Speedtest CLI. This makes it very convenient to run a speed test and manipulate the data in anyway you like. For this demonstration we are simply going to take the output of the speed test and direct it to a file for later viewing.

First, lets head on over to the and choose your preferred Linux distribution. You will then need to create a bash script and insert the following into the file based on your distribution:


sudo apt-get install gnupg1 apt-transport-https dirmngr
export INSTALL_KEY=379CE192D401AB61
sudo apt-key adv --keyserver --recv-keys $INSTALL_KEY
echo "deb generic main" | sudo tee  /etc/apt/sources.list.d/speedtest.list
sudo apt-get update
apt-get install speedtest


sudo yum install wget
wget -O bintray-ookla-rhel.repo
sudo mv bintray-ookla-rhel.repo /etc/yum.repos.d/
sudo yum install speedtest

When you’re ready, simply make it an executable with:

chmod +x ./

Run the script to install Speedtest CLI.

How to use

The speedtest program is very easy to use. All you have to do is run the following to do a simple speed test:


This will pick the closest server and measure your latency, download, and upload. If you would like to see a list of servers available nearby, you can do it like this:

speedtest -L

You will then see a list of servers and their respective IDs. This is important if you were to want to only use speedtest with a specific server with:

speedtest -s IDofserver

It is recommended to use a specific server when running your script as it will help you produce accurate results.

We are now going to create a script to run daily for our speedtest, this script will be placed in the /etc/cron.hourly directory:

nano /etc/cron.hourly/

Now we will add the following to our bash script:


/bin/echo "`date`:" >> /path/to/speedtestlog
/bin/speedtest -s ID >> /path/to/speedtestlog

Here we are using the full path to our programs. Do note that this may vary from Linux distribution and you will need to check with whereis speedtest && whereis echo to find the full path to the binary files. The first part will print our date and time to the speedtestlog file. Next, the speedtest will be ran and placed right below the date/time.

Make sure you chmod +x your file and then run it with cd /etc/cron.hourly && ./

In order to display your speedtestlog file, you can either:

cat /path/to/speedtestlog


less /path/to/speedtestlog

This is by far the easiest way of gauging your connection speed through the internet.