[Discuss] Run a command with retries

Steven Kurylo sk at infinitepigeons.org
Fri Mar 19 11:29:37 PDT 2010


> wget, and others.
>
> I'll use wget as an example:
>
> For this application success/failure depends on the context.
>
> If I 'wget' a page with <form> data and the form result returns
> nothing, according to wget HTML came back just fine.
> The form search failed though.
>
> The actual output of most programs is far more than PASS/FAIL
> and depends on the usage context of the data being returned.
>

You're asking to much of wget.  If there was a DNS error, or network
error, wget would do the right thing.

wget fetches pages and thats it.  You then need to use a tool which
checks the returned html.  From an html validator to custom parsing
code, depending on what you need.


To flesh out the last example:

TMP= /tmp/wget.$$
function work{
   #Get data
   wget http://some url > $TMP || return $?
   #Validate results
   grep $TMP keyword || return $?
   return 0
}

i=0
while [ "$i" -lt 4 ]; do
 work && break
 i=$[$i+1]
 sleep 30
done

rm $TMP &> /dev/null
more-cleanup-commands


More information about the Discuss mailing list