How to create mirror?

hello
how can i add mirror link in for command to check if mirror 1 was break, check mirror2 ?

MIRROR=http://domain1.com/file.tar.gz
MIRROR2=http://domain2.com/file.tar.gz
if [ $answer = 1 ]; then
    wget $MIRROR
    echo "$BACK2MENU" ; read
fi

Capture return code after you try and get from mirror1.

if [ $answer == 1 ]; then
    wget $MIRROR
RC="$?"
if [[ "$RC" -ne 0 ]]; then
wget $MIRROR2
fi
    echo "$BACK2MENU" ; read
fi

Why not simply re-run wget with mirror2 url, but only if mirror(1) fails.
Saves you another 'if' block.

if [ $answer = 1 ]; then
    wget $MIRROR || wget $MIRROR2
    echo "$BACK2MENU" ; read
fi

hth

what RC="$?" exactly do?
and will the data of RC drop ?
example:
i have 10 miror checker in the scriot,
i have to define RC for all of them or change it to RC3 RC4 ?
i want to know the dead time of this variable only

there are several reason when an error occurred during wget:
sometimes timeout error happened
sometimes file doesnt exist,
sometimes file exist But the server does not have permission to download

in these cases, is this methid work fine? coz all of these situation has their own error number,

RC=$? sets the variable RC, which is a synonym for Return Code, to exactly this, others use 'RET', 'ret', 'return_code' or something alike.
$? contains the return code of the previously executed command.

SriniShoo:

  1. run wget
  2. set RC to $?
  3. Compare RC with 0 (success)
  4. If anything else but 0, call wget for mirror2

sea:

  1. run wget
  2. return code is anything but 0, call wget for mirror2

So, yes, either solution will jump in upon any fail.

Of course, you could to handle the error code, in the like of (i didnt check return codes for wget):

if [ $answer == 1 ]; then
	wget $MIRROR
	RC="$?"
	case "$RC" in
	0)	echo "All done well"	;;
	1)	echo "Regular fail"
		wget $MIRROR2		;;
	*)	echo "Error: $RC"	;;
	esac
fi

hth

1 Like