Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to download multiple urls from different domains using different proxies.

It should do all these in one row of code, running curl just once:

do shell script "curl --proxy 1.2.3.4:800 http://domain1.com/somefile.txt"
do shell script "curl --proxy 2.3.4.5:80 http://www.domain2.com/otherfile.png"
do shell script "curl --proxy 3.4.5.6:8080 http://domain3.com/file.jpg"
...

This fails:

do shell script "curl --proxy 1.2.3.4:800 2.3.4.5:80 3.4.5.6:8080 http://domain1.com/somefile.txt http://www.domain2.com/otherfile.png http://domain3.com/file.jpg"

Taking the code from an answer below I tried to run

set url_list to "1.2.3.4:800 http://domain1.com/somefile.txt
2.3.4.5:80 http://www.domain2.com/otherfile.png
3.4.5.6:8080 http://domain3.com/file.jpg"

do shell script "xargs curl --proxy < " & url_list

but this fails as well.

share|improve this question
    
How does the second example fail (error message etc.)? And to the question as a whole: What do you expect from running the three downloads in one row of code? Do you want to run them in parallel? –  patrix May 11 '13 at 7:04
    
There is no need to run parallel. –  user49147 May 11 '13 at 10:56
    
What is the motivation to have it all in "one row of code" then? –  patrix May 11 '13 at 11:00

1 Answer 1

When you have a long URL or multiples, use xargs instead:

do shell script "xargs curl --proxy < url-list.txt"

url-list.txt

1.2.3.4:800 http://domain1.com/somefile.txt
2.3.4.5:80 http://www.domain2.com/otherfile.png
3.4.5.6:8080 http://domain3.com/file.jpg
share|improve this answer
    
Shouldn't you also pass -L 1 -P 3 to xargs as well to ensure that curl is called correctly and that xargs runs the downloads in parallel? –  patrix May 11 '13 at 7:20
    
@patrix, yes I normally would, although the op didn't have any of those args in their original command - so maybe they didn't want any reattempts. Proxy tunnel args are only necessary if not using HTTP protocol. –  l'L'l May 11 '13 at 13:08
    
I would pass them to xargs, not to curl. –  patrix May 11 '13 at 13:45
    
lol, ironic how those args still apply to the question in the curl aspect - but yes xargs eof and output is helpful no doubt and sorry i didn't notice that in your original comment. –  l'L'l May 11 '13 at 13:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.