How to manipulate the conditions between every retry in wget?

Hi ,

When i hit the URL using WGET command ,it is retrying according to the number of retry we mentioned along with Wget command.

my expectation :
1) If 1st try is failed and iam retrying again before 2nd retry i have to check for "xxxxxxx" entry in the log file.
2) If "XXXXXXX" entry is not available ,i have to allow 2nd retry.
3) If "XXXXXXX" entry is available,i shouldnot allow to retry again.

Can we check the condition between every retry,if yes please advice me how to achieve this..
thanks in advance.

wget isn't a programming language and can't do specified things on different numbers of retries.

You could disable retries completely and do the retry functionality yourself.

TRIES=0

while ! wget --tries=1 http://url/
do
        # Break the loop early if this is the first try and XXXX isn't found in logfile
        [ "$TRIES" -eq 0 ] && ! grep -q "XXXXXXXX" /path/to/logfile && break
        TRIES=`expr $TRIES + 1`
done

Coronna ,

Can you please give me some clear syntax for how to check the conditions between every retry?
wget --retries=3 https://url....

when first time it retries it should check the condition and second time it should check the same condition if satisfies it shouldnot allow that retry else it should allow.

Please advice me how to achieve this.

Thanks in advance.

I repeat -- you can't do what you want that way. wget isn't a programming language. It can't understand "if x do y, if z quit".

The code I gave you does what you want. It doesn't use wget's own retry feature, but runs wget repeatedly with single tries.

To make it clearer, perhaps this:

TRIES=1

while ! wget --tries=1 http://url/
do
        case "$TRIES" in
        1)     # First failure.
                # if xxxx is in logfile, try again.
                grep -q xxxxx /path/to/logfile || break
                ;;
         *)   # Second and further failures.  Break the loop.
                break
                ;;
        esac

        TRIES=`expr $TRIES + 1`
done
1 Like

Corona ,

Thanks a lot it is very helpful.