How to run a speed test using the Linux command line

This guide will show you how to run an Internet speed test from the Linux command-line interface (CLI) and cron. You will also see a sample Jenkinsfile if you want to use a Jenkins for the automation instead of cron.

Speed test command-line options

Several services offer a speed test service via the CLI. Arguably, the most notable of these are by Ookla. You could also use by Netflix. This guide will show you how to use the speed test CLI service provided by Ookla. So visit for details on using the CLI for Fast.

Speed test CLI from Ookla

Many people trust Ookla’s Speedtest CLI with its global server network. As a result, the command-line tools are well suited for DevOps.

The Speedtest CLI allows you to do the following:

  • Measure your Internet connection’s download, upload, latency, and packet loss.
  • Do a speed test without relying on a web browser.
  • Install the Speedtest CLI on macOS, Debian/Ubuntu, Fedora/Centos/Redhat, and FreeBSD.
  • Set up automated scripts to collect connection performance data.
  • View test results via CSV, JSONL, or JSON.

Install Speedtest CLI

The following install instructions is a summary from


Use the following commands to install Speedtest CLI on macOS:

brew tap teamookla/speedtest
brew update
brew install speedtest --force


You can use the following commands to install Speedtest CLI on Debian/Ubuntu:

curl -s | sudo bash
sudo apt-get install speedtest


You can use the following commands to install Speedtest CLI on Fedora/Centos/Redhat:

curl -s | sudo bash
sudo yum install speedtest


You can use use the following commands to install Speedtest CLI on FreeBSD:

sudo pkg update && sudo pkg install -g libidn2 ca_root_nss
sudo pkg add ""

Run the speed test using the CLI

The following command will run the speed test:



Retrieving configuration...
Testing from Starlink (
Retrieving server list...
Selecting best server based on ping...
Hosted by Over the Wire (Sydney) [1.32 km]: 39.851 ms
Testing download speed................................................................................
Download: 57.32 Mbit/s
Testing upload speed......................................................................................................
Upload: 13.59 Mbit/s

The following command will run the speed test and produce JSON output:

speedtest-cli --json


{"download": 45898976.19254001, "upload": 17945425.352851078, "ping": 53.928, "server": {"url": "", "lat": "-33.8600", "lon": "151.2111", "name": "Sydney", "country": "Australia", "cc": "AU", "sponsor": "Digital Pacific", "id": "5744", "host": "", "d": 1.3224649556794528, "latency": 53.928}, "timestamp": "2021-10-23T20:22:26.022297Z", "bytes_sent": 24059904, "bytes_received": 57511476, "share": null, "client": {"ip": "", "lat": "-35.8672", "lon": "161.1997", "isp": "Starlink", "isprating": "3.7", "rating": "0", "ispdlavg": "0", "ispulavg": "0", "loggedin": "0", "country": "AU"}}

Choose a speed test server

You can choose a specific speed test server using the following command:

speedtest-cli --list


Retrieving configuration...
 2173) Internode (Sydney, Australia) [1.32 km]

Consequently, you can then specify your preferred server using the following command:

speedtest-cli --server 2173

Does speedtest-cli not execute when scheduled using cron?

There are a few reasons why the speedtest-cli command may fail when running it via cron:

  • First, make sure the path to speedtest-cli is set. Thus call: /usr/bin/speedtest-cli instead of just speedtest-cli.
  • Next, make sure you set “#!/bin/bash” in your bash script.

How to execute the speedtest-cli via Jenkins

The following script runs the speedtest-cli via a Jenkins pipeline and then uploads the JSON file to AWS S3.

pipeline {

    agent any

    stages {
        stage('Run test') {
            steps {
                    echo "Send speedtest data to: ${WORKSPACE}/${currentBuild.startTimeInMillis}.json"

                    echo "Create the script file"
                    script {
                       def data = "#!/bin/bash\n/usr/bin/speedtest-cli --json > ${WORKSPACE}/${currentBuild.startTimeInMillis}.json"
                       writeFile(file: '', text: data)  
                    echo "Set the execute permissions"
                    sh "chmod +x"
                    echo "Run the test script"
                    sh "./"

        stage('Upload to S3') {
            steps {
                    echo "Upload ${currentBuild.startTimeInMillis}.json s3://speedtest-results-starlink/ to S3"
                    sh "aws s3 cp ${currentBuild.startTimeInMillis}.json s3://speedtest-results-starlink/"


    post { 
        always { 

            echo 'Cleaup'
            sh "rm ${WORKSPACE}/*.json"



Wrapping up

You can now run an Internet speed test from the Linux command-line interface (CLI), cron, and Jenkins.

You may also be interested in


About the Authors

Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee

About Anto Online

Having started his career in 1999 as a Desktop Support Engineer, Anto soon changed paths and became a developer. After several years of development experience, he transitioned into a consultant. As an enterprise application consultant for a leading SaaS software provider, Anto specializes in AWS's serverless technologies. By day, Anto focuses on helping customers leverage the power of serverless technologies. By night, he indulges his passion for cloud computing by playing with Python and trying out things that are currently beyond the scope of his work. Sometimes Anto needs help as there are not enough hours at night. So Anto relies on a team of fellow Cloud enthusiasts to help him out. Each one is a Cloud expert in their own right, and Anto takes great pride in helping them learn and grow.

View all posts by Anto Online →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.