I have a script which will be running in each server and copies certain files into it. Script knows where I am running and what files I need to copy.
Script will copy files from local datacenter local_dc
but if it is down or not responding, then it will copy same files from remote datacenter remote_dc_1
and if that is also down, then it will copy same files from another remote datacenter remote_dc_2
as shown below.
Now Let's say if local_dc
machine is down, then it will copy files from remote_dc_1
machine so I need to send out an email saying this machine is down so copying from other remote machine. I don't want to send multiple emails if local_dc machine is down so I am sending emails at the end so that I get only one email instead of multiple emails for each file.
Below is my script -
do_Copy() {
el=$1
PRIMSEC=$2
scp david@"$local_dc":"$dir3"/new_weekly_2014_"$el"_200003_5.data "$PRIMSEC"/. \
|| (a=1 && scp david@"$remote_dc_1":"$dir3"/new_weekly_2014_"$el"_200003_5.data "$PRIMSEC"/.) \
|| (b=2 && scp david@"$remote_dc_2":"$dir3"/new_weekly_2014_"$el"_200003_5.data "$PRIMSEC"/.) \
|| (c=3 && exit 1)
}
export -f do_Copy
parallel --retries 10 -j 10 do_Copy {} $PRIMARY ::: "${PRIMARY_PARTITION[@]}" &
parallel --retries 10 -j 10 do_Copy {} $SECONDARY ::: "${SECONDARY_PARTITION[@]}" &
wait
# problem is this doesn't work at all?
if [ $a -eq 1 ]
then
echo "Local machine $local_dc was down, so copied from Primary Remote machine $remote_dc_1" | mailx -r "david@host.com" -s "$local_dc machine down" "david@host.com"
fi
if [ $b -eq 2 ]
then
echo "Primary Remote machine $remote_dc_1 was down, so copied from Secondary Remote machine $remote_dc_2" | mailx -r "david@host.com" -s "$remote_dc_1 machine down" "david@host.com"
fi
if [ $c -eq 3 ]
then
echo "All three machine's are down. Exiting out." | mailx -r "david@host.com" -s "All three machine's are down" "david@host.com"
fi
Is there anything wrong I am doing in my subshell with variable a, b and c?