Copy file from one server to multiple server

can some one help me to write a shell script that copy one file from one server to multiple server
ex:suppose i wnt to copy file abc.txt which is in server 1
to server2,server3,server4....:confused:

simple way is.,

scp abc.txt user@server1:/PATH
scp abc.txt user@server2:/PATH
scp abc.txt user@server3:/PATH

If you have the 'password less login' it will not ask password, else it will. And copies the file...

Or you are looking for something more sophisticated ?!

Another way is to write a script:

#server 1:

ftp -n xx.xx.xx.xx << EOF1
user user_name password
cd /path
ascii
prompt off
get abc.txt
EOF1

server 2:

ftp -n xx.xx.xx.xx << EOF2
user user_name password
cd /path
ascii
prompt off
get abc.txt
EOF2

etc etc...

If you want to do it by yourself you can do it like thegeek suggested.
Hope this helped.

there is lots of server there
so is there any other way to??

You can try the following script -


for SVR in server1 server2 server3
do
  scp2 -q <filename>  user@SVR:/PATH
done

make two files
unpwd file contains username and password with : as delimiter
serverlistfile with list of destination servers

try do something like this, but something can be made with:

awk 'getline unpwd "$usernamefile"; split(unpwd,a,':')
	{print "scp file.txt "$a[0]"@"$0":PATH"<< $a[1]}' $serverlistfile | sh

experts ur thoughts pls.

for SVR in < 'cat serverlist'
do
  scp2 -q <filename>  user@SVR:/PATH
done

same as above but reading in file serverlist. just create file with list of all servers. If you have ssh keys setup that would be best as well, to allow no pw.

Or this:

#!/bin/bash
#
# This script will copy a file to all hosts listed in serverlist file
# Place file  to copy and fix paths below.
#
# Edit /root/serverlist file with hostname you need.
#
# Edit file variable with location of file you want to scp
#
# Edit desst variable with directory path where you want file to be copied.
#
HOSTS=/root/serverlist
file=/sourcefile
dest=/dest/location
echo "Are you sure you want to copy $file to the  standard list of servers"
echo "This may take a while!!"
echo -n "Enter 'y' or 'n':"
read CHOICE
case "$CHOICE" in
        y|yes|Yes) while read line
do
        scp $file $line:$dest
done < $HOSTS
        continue ;;
     n|no|No) echo "Please try again"

esac