I am trying to copy files from testMachineB and testMachineC into testMachineA as I am running my shell script on testMachineA.
If the file is not there in testMachineB, then it should be there in testMachineC for sure. So I will try to copy file from testMachineB first, if it is not there in testMachineB then I will go to testMachineC to copy the same files.
PARTITIONS is the file partition number which I need to copy in testMachineA in directory FOLDER_LOCATION.
#!/bin/bash
readonly FOLDER_LOCATION=/export/home/username/pooking/primary
readonly MACHINES=(testMachineB testMachineC)
PARTITIONS=(0 3 5 7 9 11 13 15 17 19 21 23 25 27 29) # this will have more file numbers around 400
dir1=/data/snapshot/20140317
# delete all the files first
find "$FOLDER_LOCATION" -mindepth 1 -delete
for el in "${PARTITIONS[@]}"
do
scp -o ControlMaster=auto -o 'ControlPath=~/.ssh/control-%r@%h:%p' -o ControlPersist=900 username@${MACHINES[0]}:$dir1/s5_daily_1980_"$el"_200003_5.data $FOLDER_LOCATION/. || scp -o ControlMaster=auto -o 'ControlPath=~/.ssh/control-%r@%h:%p' -o ControlPersist=900 username@${MACHINES[1]}:$dir1/s5_daily_1980_"$el"_200003_5.data $FOLDER_LOCATION/.
done
Problem Statement:-
Now what I am trying to do is - Split the PARTITIONS array which contains the partition number in set of five files. So I will copy first set which has 5 files in parallel. Once these five files are done, then I will move to next set which has another five files and download them in parallel again and keep on doing this until all the files are done.
I don't want to download all the files in parallel, just five files at a time.
Is this possible to do using bash shell scripting?
Update:-
Something like this you are suggesting?
echo $$
readonly FOLDER_LOCATION=/export/home/username/pooking/primary
readonly MACHINES=(testMachineB testMachineC)
ELEMENTS=(0 3 5 7 9 11 13 15 17 19 21 23 25 27 29)
LEN_ELEMENTS=${#ELEMENTS[@]}
X=0
dir1=/data/snapshot/20140317
function download() {
if [[ $X < $LEN_ELEMENTS ]]; then
(scp -o ControlMaster=auto -o 'ControlPath=~/.ssh/control-%r@%h:%p' -o ControlPersist=900 username@${MACHINES[0]}:$dir1/s5_daily_1980_"${ELEMENTS[$X]}"_200003_5.data $FOLDER_LOCATION/. || scp -o ControlMaster=auto -o 'ControlPath=~/.ssh/control-%r@%h:%p' -o ControlPersist=900 username@${MACHINES[1]}:$dir1/s5_daily_1980_"${ELEMENTS[$X]}"_200003_5.data $FOLDER_LOCATION/.) && kill -SIGHUP $$ 2>/dev/null &
fi
}
trap 'X=$((X+1)); download' SIGHUP
# delete old files
find "$FOLDER_LOCATION" -mindepth 1 -delete
# initial loop
for x in {1..5}
do
download
done
# waiting loop
while [ $X -lt $LEN_ELEMENTS ]
do
sleep 1
done
Does above looks right? And also, now where do I put my delete command?

