I am trying to copy files from machineB
and machineC
into machineA
as I am running my shell script on machineA
.
If the files are not in machineB
, then it should be there in machineC
for sure. I will try copying the files from machineB
first, and if it is not in machineB
, then I will try copying the same files from machineC
.
I am copying the files in parallel using GNU parallel library and it is working fine. I am currently copying two files in parallel.
Earlier, I was copying the PRIMARY_PARTITION
files in PRIMARY
folder using GNU parallel and once that was done. I was then copying the SECONDARY_PARTITION
files in the SECONDARY
folder using same GNU parallel so it is sequential as of now with regards to the PRIMARY
and SECONDARY
folders.
Now I decided to copy files in PRIMARY
and SECONDARY
folder simultaneously.
#!/bin/bash
export PRIMARY=/test01/primary
export SECONDARY=/test02/secondary
readonly FILERS_LOCATION=(machineB machineC)
export FILERS_LOCATION_1=${FILERS_LOCATION[0]}
export FILERS_LOCATION_2=${FILERS_LOCATION[1]}
PRIMARY_PARTITION=(550 274 2 546 278) # this will have more file numbers
SECONDARY_PARTITION=(1643 1103 1372 1096 1369 1568) # this will have more file numbers
export dir3=/testing/snapshot/20140103
do_Copy() {
el=$1
PRIMSEC=$2
scp david@$FILERS_LOCATION_1:$dir3/new_weekly_2014_"$el"_200003_5.data $PRIMSEC/. || scp david@$FILERS_LOCATION_2:$dir3/new_weekly_2014_"$el"_200003_5.data $PRIMSEC/.
}
export -f do_Copy
parallel --retries 10 -j 5 do_Copy {} $PRIMARY ::: "${PRIMARY_PARTITION[@]}" &
parallel --retries 10 -j 5 do_Copy {} $SECONDARY ::: "${SECONDARY_PARTITION[@]}" &
wait
echo "All files copied."
The script is working fine for me, but I am trying to see is there any better way of doing the same thing using GNU Parallel instead of using &
.