View Single Post
Posts: 299 | Thanked: 557 times | Joined on Aug 2012
#4592
Originally Posted by Schturman View Post
brkn, i have another little question..
In option C user can download both instruction (Russian and English). Instead creating two scripts, how i can edit your script for downloading both files?
Thanks.

EDIT:
I just added the second script with another link below the first one, all in to one script, maybe it not right, but it work
Quick and dirty:
+ dropped curl (wget only now)
- still needs some work in while loop/progress for full dynamic array of files

Code:
#!/bin/bash

bar="========================================"
barlength=${#bar}
FOLDER="https://dl.dropbox.com/u/17706605"
FILE[0]="N9_QuickTweak_en_v9.4.pdf"
FILE[1]="N9_QuickTweak_ru_v9.4.pdf"

echo "Calculating download size ..."

for (( i = 0 ; i < ${#FILE[@]} ; i++ ))
do
    if [ -f "${FILE[$i]}" ] ; then rm -f "${FILE[$i]}" ; fi
    length=$(wget "$FOLDER/${FILE[$i]}" --spider --server-response -O - 2>&1 | sed -ne '/Content-Length/{s/.*: //;p}')
    totallength=$(($totallength + $length))
    touch "${FILE[$i]}"
    nice -n 19 wget -N -q "$FOLDER/${FILE[$i]}" 2>/dev/null &
done

echo "Downloading $totallength bytes"

tmp=1
totaltmp=1

while [[ $totaltmp -lt $totallength ]]; do
    tmp1=$(stat "${FILE[0]}" | grep Size | awk '{print $2}')
    tmp2=$(stat "${FILE[1]}" | grep Size | awk '{print $2}')
    totaltmp=$(($tmp1 + $tmp2))
    n=$(($totaltmp * $barlength / $totallength))
    percent=$((100 * $totaltmp / $totallength))
    printf "\r[%-${barlength}s]" "${bar:0:n}"
    printf " $percent%%"
    sleep 0.1
done
printf "\n"

Last edited by brkn; 2012-11-11 at 15:08.
 

The Following User Says Thank You to brkn For This Useful Post: