Librespeed - Set server with own script

Since librespeed on my Omnia Turris always chooses a bad test-server and it isn’t possible to force it using a specific server, I tried something and it seems working surprisingly fine.

In short I wrote a script that runs librespeed-cli with a defined test-server and changed the librespeed-cronjob accordingly. The script does the test, saves the result as json and afterwards move the json to the configured librespeed-directory. This seems enough for the librespeed gui to display the results as it does with it’s own (all Turris checks in the screenshot are done by my script).

The shell-script:
vi /srv/librespeed/test.sh

#! /bin/bash

#Define where to store the results
data_dir="/srv/librespeed"
#Create a folder in format YYYY-MM like Turris librespeed does
folder=$(date +%Y'-'%m)
#Final folder-path to store the results
data_dir=$data_dir/$folder

#Run librespeed-cli and store the output as json
librespeed-cli --ipv4 --json --server 85 > $data_dir/test.json

#Get timestamp from json to name the file correctly
TMSTMP="$(jq -r .[].timestamp $data_dir/test.json)"

#Rename json
mv $data_dir/test.json $data_dir/$TMSTMP.json

Editing the already existing cron-job:
vi /etc/cron.d/librespeed

#~ 1~4,13~16 * * * root /usr/libexec/foris-controller/librespeed.sh
~ 1~4,13~16 * * * root /srv/librespeed/test.sh

As I’m no scripting- or linux-pro, there sure is a lot to optimize. Any tips are welcome. Especially regarding the cron job and preventing all of this from getting overwritten by an update.

3 Likes