3

Server: Ubuntu 20.04.2 LTS

Command: speedtest | speedtest-cli

I have a bash script to identity download & upload speed every 15 mins. When i execute it manually it works well but not on cron.

1st time, Suppose at 12:00 it executes properly and following is the output

Testing from AT&T Services (12.26.3.241)...

Retrieving speedtest.net server list...

Selecting best server based on ping...

Hosted by AWI networks (St. George, UT)

Testing download speed.........................................................................

Download: *** Mbit/s

Testing upload speed......................................................................

Upload: *** Mbit/s

2nd time, 12:15 :-

Retrieving speedtest.net configuration...

Testing from AT&T Services (12.26.3.241)...

Retrieving speedtest.net server list...

Selecting best server based on ping...

And when I check user's mail, Following is the error :-

ERROR: Unable to connect to servers to test latency.

1
  • any question? how to help with no view on the script and no view on the cron task ?
    – cmak.fr
    Mar 10, 2021 at 6:58

4 Answers 4

4

Same Problem here. It seams link the Server is overloaded at specific times. My cron-expression is "0 /15 * 1/1 * ? *" so the Job started: 10:00, 10:15, 10:30 ...

I changed the cron-expression to "0 4/15 * 1/1 * ? *" so the job starts: 10:04, 10:19, 10:34 ...

Solved the problem for me.

Kind Regards

2
  • 1
    Started facing the same problem. Queries at 00 minutes would fail. Changed to a different minute within the hour and it worked!
    – Daniel
    Mar 17, 2021 at 17:19
  • 1
    Jobs at 0 and 30 failed repeatedly, but offsetting the jobs with some minutes delay solved the issue for me. --timeout has no effect, error ERROR: Unable to connect to servers to test latency. occurs within seconds.
    – marianoju
    Nov 3, 2021 at 10:05
0

The classic reason for cron jobs not working when the same job works on the command line is that the environment is different. You can fix that with the following:

  1. Place the commands you want to run in a script not forgetting to add the shebang.
  2. Add a source command before the commands you want to run so that your .bashrc configuration is loaded.
  3. Make sure your script is executable.
  4. Adjust cron to run the script using the full path to the script.
    source /path/to/your/.bashrc

Good luck!

0

try adding following flags to your .sh script, it solved problem for me:

My script run_speedtest.sh:

#!/bin/bash
speedtest --accept-license --accept-gdpr >> /home/xxx/speedtesty/results

Crontab entry:

/10 * * * * /bin/bash /home/xxx/speedtesty/run_speedtest.sh
0

I found the answer to this - if you put a script in cron you need to not use "" to encase the command you want to run. The script works on the command line like this, but not in cron. Use '' to encase the command instead as follows (I use the csv option so I can do something with the results):

I create a variable called SPEEDTEST to run the command as follows, then run it using $SPEEDTEST

SPEEDTEST='/usr/local/bin/speedtest --csv'

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.