I'm trying to use curl in a script I'm developing that will download a bunch of files. I used -#
switch with curl to force showing progress bar instead of full details which are not of interest. However, the output looks something like that:
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
This is not descriptive at all and I thought of adding a line before any download to show what is going to be downloaded but I did not like the result. I'm asking if there is a way for curl to output something like what we get from wget:
file1.zip 100%[=============================>] 33.05K --.-KB/s in 0.1s
file2.zip 100%[=============================>] 46.26K --.-KB/s in 0.1s
file3.zip 100%[=============================>] 19.46K --.-KB/s in 0.1s
I don't want to use wget instead, though, as it is not available for OS X by default and will require whoever going to use my script to install wget first using port or other methods which is inconvenient.
I found a good way to solve this by using curl-progress script here (https://gist.github.com/sstephenson/4587282) which wraps curl with a custom-drawn progress bar.
By default, the script curl-progress does not show file name in front of the progress bar but it is totally customisable. I had to modify print_progress function so it use one additional argument which is the name of the file to be downloaded. Therefor, I modified the printf statement inside print_progress so it print the file name in suitable location before the progress bar:
print_progress() {
local bytes="$1"
local length="$2"
local fileName="$3" # I added this third variable
...
...
printf "\x1B[0G %-10s%-6s\x1B[7m%*s\x1B[0m%*s\x1B[1D" \
"$fileName" "${percent}%" "$on" "" "$off" "" >&4
}
Now print_progress method expect three arguments and for that I modified the call to print_progress to send the third argument:
print_progress "$bytes" "$length" "$2"
Where $2 refers to the second argument sent to curl-progress. Now this is an example to download an arbitrary file from the web:
$ ./curl-progress -so "file1.zip" "http://download.thinkbroadband.com/20MB.zip"
And this is the output:
I will still have to ship a copy of curl-progress script along with mine but it is better than asking the user to install wget first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With