1

I want to automate speedtest.net and test my network connection to specific server ID 36250 every 5 minutes.

Ive installed official speedtestCLI and wrote a script called run_speedtest.sh

#!/bin/bash

date_now=`date "+%H:%M:%S       %d/%m/%y"`
result=/home/zaz/speedtesty/results
speedtest -s 36250 >> result
echo "$date_now" >> result

Now to automate things Ive edited my crontab file by using command: sudo crontab -e and it looks like this:

*/5 * * * * /bin/bash /home/zaz/speedtesty/run_speedtest.sh

results file is created, however only output in my results file are rows with current date. If I run script by typing bash run_speedtest.sh I get output in results that I want (speedtest measure + date)

Im a Ubuntu newbie, can someone help me out?

1
  • How did you install the speedtest CLI? – muru Mar 11 at 10:42
1

If run via cron, the script runs with different permissions (with a different user account) than when you run it from the shell. So it might or might not find your speedtest command; specify the full path for it.

Also, since you create a variable result in the script, you probably want to use the variable, not a plain file result in the current directory (which is probably the root directory when run via cron, and writing there may fail because of permissions). Use >>$result, not >> result.

And finally, I'd simply use a loop and sleep 600 (sleep for 600 seconds) instead of going through the hassle with a crontab which you might forget sooner or later, and then you keep speed-testing forever. ;-)

1
  • "the script runs with different permissions (with a different user account)" Depends on which crontab you added it to. OP could have added it to their crontab, in which case it would have run as their user.. – muru Mar 11 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.