Download multiple pages with curl at the same address without overwriting

0

I need to download this page multiple times, it returns a different result each time it is accessed:

i="0"

while [ $i -lt 10 ]; do
    curl -O http://httpbin.org/bytes/128
    i=$[$i+1]
done

But every time the curl command is executed, the previous file is overwritten, since the name is the same.

How do I not overwrite? Names could be sequential ex. "128 (1)", "128 (2)", ..., "128 (n)".     

asked by anonymous 28.10.2016 / 23:30

2 answers

1

Use the -o (the lowercase) option to specify where to write the response and use your counter as the filename:

i=0; 
while [ $i -lt 10 ]; do 
    curl http://httpbin.org/bytes/128 -o 128_$i
    i=$[$i+1]
done

Or more clearly using for :

for i in {1..10}; do 
    curl http://httpbin.org/bytes/128 -o 128_$i
done

Or rather by using seq :

seq -f 'curl http://httpbin.org/bytes/128 -o 128_%g' 9 | bash
    
28.10.2016 / 23:49
1

Good night, well curl can be used with -o to set a file for output, as explained in the international stack overflow: link

  

curl -K myconfig.txt -o output.txt

     

Writes the first output received in the file you specify.

     

curl -K myconfig.txt> > output.txt

     

Appends all output you receive to the specified file.

So you can use the declared variable to name the files.

    
28.10.2016 / 23:37