Hi,
I have a requirement to RCP the files from remote server to local server.
Also the RCP has to run in parallel. However using 'xargs' retrives 2 file names during each loop. How do we restrict to only one file name using xargs and loop till remaining files.
I use the below code for that..
set -x
SOURCESERVER=ss01
SOURCEDIR="/home/oracle/senthil"
TARGETDIR="/home/oracle/senthil"
MAX_PARALLEL=2
nroffiles=`ssh $SOURCESERVER "ls $SOURCEDIR|wc -w"`
echo $nroffiles
setsize=$(( nroffiles/MAX_PARALLEL ))
echo $setsize
ssh -n $SOURCESERVER ls -1 $SOURCEDIR/ | xargs -n $setsize | while read workset; do
ssh -n $SOURCESERVER scp -rp $SOURCESERVER:$SOURCEDIR/$workset . &
done
Here's the runtime log. As you can see there are two files passed -(a&b
c&d) during each loop processing. How can we restrict this to one file at a time.
[oracle@ss02 senthil]$ ./pull_data.ksh
++ SOURCESERVER=ss01
++ SOURCEDIR=/home/oracle/senthil
++ TARGETDIR=/home/oracle/senthil
++ MAX_PARALLEL=2
+++ ssh ss01 'ls /home/oracle/senthil|wc -w'
++ nroffiles=5
++ echo 5
5
++ setsize=2
++ echo 2
2
++ ssh -n ss01 ls -1 /home/oracle/senthil/
++ xargs -n 2
++ read workset
++ ssh -n ss01 scp -rp ss01:/home/oracle/senthil/a b .
++ read workset
++ ssh -n ss01 scp -rp ss01:/home/oracle/senthil/c d .
++ read workset