3

I save images with:

#!/bin/bash
for i in {1..30000}
do
    wget "http://services.runescape.com/m=itemdb_rs/3809_obj_sprite.gif?id="$i
done

Is there a way to speed up the process? Sometimes a URL does not exist and I get:

connected.
HTTP request sent, awaiting response... 404 Not found
2012-08-04 18:09:36 ERROR 404: Not found.

How can I continue after this error?

3
  • If you have an additional question about how to download out only certain object, please ask an additional question. Mixing two subjects in one question just over-complicates the matter :) – Der Hochstapler Aug 4 '12 at 16:26
  • @OliverSalzburg - Your comment is spot on. But you chose to edit the title to reflect the question you answered. Neglecting to notice that there where two answers answering his other question. – Nifle Aug 4 '12 at 16:37
  • @Nifle: Feel free to read the history of the question and change it if you feel that I've missed the point with my edit. Also, please note that I edited and commented on the question before I wrote my answer. – Der Hochstapler Aug 4 '12 at 16:39
9

Try

wget "http://s.../m=itemdb_rs/3809_obj_sprite.gif?id="$i || true

This way, if wget fails, the result of that line is still zero and your script continues.

To learn how to properly handle errors in a bash script, check out the following resources:

0
1

You could try something like this.

#!/bin/bash
for i in {1..30000};
do 
x="http://64.79.147.130/m=itemdb_rs/3809_obj_sprite.gif?id="$i
if [[ $(echo $(GET -sd $x | grep "404")) = "" ]]; 
then 
wget --no-dns-cache -nc -U"Firefox/10" $x 2>&1 \
| grep "Saving" | sed 's,Saving to,Saved,'; 
fi 
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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