I'm trying to measure my internet connection regulary using speedtest-cli
- speedtest-cli is installed on my NAS (DSM 6.2.4-25556 Update 7 on DS413j)
- I wrote the bash script below
- I created a task in task planner (for user root) with the following command: bash /volume1/Andy/_bandbreitenmessung/speedtest.sh
Script:
#!/bin/bash
printf -v date '%(%Y-%m-%d %H:%M:%S)T\n' -1
WD=$(/bin/dirname $0)
echo "${date}" >> $WD/log.txt
DataFile=$WD/data.csv
if [ ! -f $DataFile ]then
echo " DataFile (csv-header): ${DataFile}" >> $WD/log.txt
$WD/speedtest-cli/speedtest-cli --csv-header > $DataFile
echo " - Header geschrieben" >> $WD/log.txt
fi
echo " DataFile (csv): ${DataFile}" >> $WD/log.txt
$WD/speedtest-cli/speedtest-cli --csv >> $DataFile
echo " - Daten geschrieben" >> $WD/log.txt
I'm experiencing the following behavior:
- Whenever I'm executing the task from withing task scheduler manually it works like a charm:
- if data file doesn't exist speedtest-cli --csv-header gets executed which creates the data file with the header row and speedtest-cli --csv also gets executed adding the first data row into the data file
- each consecutive manual execution ignores the if statement (as the data file is already present), so only speedtest-cli --csv gets executed adding another data row into the data file
- log.txt gets written as expected
- When the scheduled execution is done the behavior is almost the same with the except that I do not get the data rows into the data file, so the command speedtest-cli --csv does not work as expected.
Any ideas why manual vs. schedule execution results in different behaviour?
It turned out that speednet-cli --csv seems to fail on top of the hour (x:00) and at x:30 with "ERROR: Unable to connect to servers to test latency.". I assume this is down to too many users running speedtest-cli in a scheduled fashion at those times. I will configure the scheduled task to execute the script outside those times.