How to grep download speed from wget output?

后端 未结 5 1734
挽巷
挽巷 2020-12-10 06:58

I need to download several files with wget and measure download speed.

e.g. I download with

wget -O /dev/null http://ftp.bit.nl/pub/Open         


        
5条回答
  •  悲哀的现实
    2020-12-10 07:22

    Update, a grep-style version using sed:

    wget ... 2>&1 | sed -n '$,$s/.*(\(.*\)).*/\1/p'
    

    Old version:

    I thought, it's easier to divide the file size by the download time after the download. ;-)

    (/usr/bin/time -p wget ... 2>&1 >/dev/null; ls -l newfile) | \
    awk '
       NR==1 {t=$2};
       NR==4 {printf("rate=%f bytes/second\n", $5/t)}
    '
    

    The first awk line stores the elapsed real time of "real xx.xx" in variabe t. The second awk line divides the file size (column 5 of ls -l) by the time and outputs this as the rate.

提交回复
热议问题