0

UPDATE:

This question has been closed. I asked in another question. Bash how to run multiple wget with output by sequence (NOT Parallel) and delete the wget file for speedtest purpose

I used timeout solution

#!/bin/bash

function speedtest() {

    local key=$1
    local url=$2

    timeout 10 wget $url
    echo -e "\033[40;32;1m$key is completed.\033[0m"

 
}

speedtest "Lisbon" "https://lg-lis.fdcservers.net/100MBtest.zip"
speedtest "London" "https://lg-lon.fdcservers.net/100MBtest.zip"
speedtest "Madrid" "https://lg-mad.fdcservers.net/100MBtest.zip"
speedtest "Paris" "https://lg-par2.fdcservers.net/100MBtest.zip"

When I run the bash script, this is the output.

» ./wget_speedtest.sh                                                                                       [2021/05/8 |15:42:49]

Redirecting output to ‘wget-log’.
Lisbon is completed.

Redirecting output to ‘wget-log.1’.
London is completed.

Redirecting output to ‘wget-log.2’.
Madrid is completed.

Redirecting output to ‘wget-log.3’.
Paris is completed.

I am expected to see the kb/s for running after 10 seconds for each wget.


I have a list of wget of file to download and want to see the download speed. I just want to run about 10 seconds, then print out the result what is the download speed. I have 20 different server file to test out. My goal is to see the how kb/s download for that 10 seconds.

e.g

> wget https://lg-lis.fdcservers.net/100MBtest.zip                                                          
--2021-05-08 13:37:37--  https://lg-lis.fdcservers.net/100MBtest.zip
Resolving lg-lis.fdcservers.net (lg-lis.fdcservers.net)... 50.7.43.4
Connecting to lg-lis.fdcservers.net (lg-lis.fdcservers.net)|50.7.43.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/zip]
Saving to: ‘100MBtest.zip’

100MBtest.zip                      0%[                                                         ] 679.66K   174KB/s    eta 9m 26s ^C

This is my bash file

#!/bin/bash

function speedtest() {

    local key=$1
    local url=$2

     ( cmdpid=$$; 
     (sleep 10; kill $cmdpid; rm -f 100M) \
        & while ! wget "$url"
      do 
          echo -e "\033[40;32;1m$key for 10 seconds done.\033[0m"
      done )

 
}
speedtest "Lisbon" "https://lg-lis.fdcservers.net/100MBtest.zip"
speedtest "London" "https://lg-lon.fdcservers.net/100MBtest.zip"
speedtest "Madrid" "https://lg-mad.fdcservers.net/100MBtest.zip"
speedtest "Paris" "https://lg-par2.fdcservers.net/100MBtest.zip"

However, the above code does not work, it still download at background and redirect to wget-log

> ./wget_speedtest.sh                                                                                       
--2021-05-08 13:41:56--  https://lg-lis.fdcservers.net/100MBtest.zip
Resolving lg-lis.fdcservers.net (lg-lis.fdcservers.net)... 50.7.43.4
Connecting to lg-lis.fdcservers.net (lg-lis.fdcservers.net)|50.7.43.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100M’

100M                             5%[==>                                                      ]   5.84M  1.02MB/s    eta 79s    [1]    21251 terminated  ./wget_speedtest.sh

Redirecting output to ‘wget-log’.
Shiro
  • 7,344
  • 8
  • 46
  • 80

1 Answers1

1

Use the timeout command (part of GNU coreutils):

$ timeout 10 wget https://lg-lis.fdcservers.net
/100MBtest.zip
--2021-05-07 22:53:20--  https://lg-lis.fdcservers.net/100MBtest.zip
Resolving lg-lis.fdcservers.net (lg-lis.fdcservers.net)... 50.7.43.4
Connecting to lg-lis.fdcservers.net (lg-lis.fdcservers.net)|50.7.43.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/zip]
Saving to: ‘100MBtest.zip’

100MBtest.zip         0%[                    ]  23.66K  10.8KB/s               
$ 

If the specified time is exceeded, timeout exits with a status of 124.

timeout --help or info coreutils timeout for more information.

If you're on MacOS, see Timeout command on Mac OS X? for some suggested alternatives.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631