I'm just trying to use rsync to retreive the file from different servers with script. i want to look for a file, if the file exists, then retreive the file from different servers, and put it in one file. I have the following command.
rsync -v -e ssh jerry@openbsd.nixcraft.in:~/webroot.txt /tmp
any idea how to write the script. Thanks
pludi
July 29, 2009, 11:34am
2
If you've got SSH, and want to receive only one file from a fixed location:
scp <user>@<host>:webroot.txt /tmp/.
An example would be:
for i in srv1 srv2 srv3
do
scp <user>@${i}:webroot.txt /tmp/.
cat /tmp/webroot.txt >> /tmp/webroot_all.txt
done
for i in srv1 srv2 srv3
do
ssh <user>@${i} 'cat /path../webroot.txt 2>&1' >> /tmp/webroot_all.txt
done
Cool thats working great. But I also want to remove the file once it scp the file from remore host to localhost. can we do that? Thanks
for i in srv1 srv2 srv3
do
file=/path../webroot.txt
ssh <user>@${i} "cat $file 2>&1;rm -f $file" >> /tmp/webroot_all.txt
done