LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to transfer multiple file to multiple server using public and private key (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-transfer-multiple-file-to-multiple-server-using-public-and-private-key-931554/)

sampadray81 02-27-2012 09:36 AM

how to transfer multiple file to multiple server using public and private key
 
Hi,

I have 10 100 MB files in a single server.

I want to copy those files into 20 different servers at a single go. Do we have any commands to do the same. Or do we have to follow a particular process to do the same like defining a public and private key. If so how do we do that.

Any suggestions would be highly appreciated.

Regards,
Sampad Ray

acid_kewpie 02-27-2012 09:41 AM

copying files and public keys have nothing in common. If you have ssh working with keys, then you can use scp / sftp to copy fiels between those systems, sure, but it's nonsense to say you're copying them with a key.

sampadray81 02-27-2012 09:54 AM

Actually i had a interview question asking what would you do if you want to copy multiple files residing in a server to multiple servers at once rather than by doing it one at a time.

sampadray81 02-27-2012 10:01 AM

i found this code in the forum:

#/usr/bin/sh
# This is a script to copy files from one host to a group of hosts

# There are three variables accepted via commandline
# $1 = first parameter (/source_path/source_filename)
# $2 = second parameter (/target_directory/)
# $3 = third paramter (file that contains list of hosts)

SOURCEFILE=$1
TARGETDIR=$2
HOSTFILE=$3

if [ -f $SOURCEFILE ]
then
printf "File found, preparing to transfer\n"
while read server
do
scp -p $SOURCEFILE ${server}:$TARGETDIR
done < $HOSTFILE
else
printf "File \"$SOURCEFILE\" not found\n"
exit 0
fi
exit 0


but want to have a command to do it.

Tinkster 02-27-2012 11:12 AM

Quote:

but want to have a command to do it.
Well ... you got it, you just posted it.
Code:

while read server
do
scp -p $SOURCEFILE ${server}:$TARGETDIR
done < $HOSTFILE[

Put all that on one line.


If you don't want a "host file" you could change it to a
for loop.
Code:

for server in server1 server2 server3 ...; do scp -p file ${server}:/path/to/target; done

Of course your interviewers might have been after a response like:
"I'd use cfengine", or "Puppet, of course", or,
"Depending on the existing snmp infrastructure I'd utilise ... "

So many options ...


Cheers,
Tink

acid_kewpie 02-27-2012 12:31 PM

Ahh, I misread your question a fair bit. My bad.

Yeah, puppet all the way! or Func. they would be MY weapons of choice.


All times are GMT -5. The time now is 05:01 PM.