Operating System - HP-UX
1834020 Members
2824 Online
110063 Solutions
New Discussion

Re: need a script to copy a file to 5 servers

 
SOLVED
Go to solution
Jagadesh_2
Regular Advisor

need a script to copy a file to 5 servers

Hi,

I need to copy a file from server1:/tmp/test.tar to other servers(server2,3,4,5,6..:/home/user1/TST)directory.

The TST directory needs to be created before copying the file. I tried ssh from server1 (ssh server2 "mkdir /home/user1/TST").. the comand executes but it is not creating a directory.

Please let me know how to go ahead in doing this activity via a script from server1.

Many Thanks
S.Jagadesh
3 REPLIES 3
Raj D.
Honored Contributor
Solution

Re: need a script to copy a file to 5 servers

Hi Jagadesh ,

You can try the foloowing script running from server1.

#!/usr/bin/ksh
# copying server1:/tmp/test.tar to server2,3,4,5,6.. /home/user1/TST/
########################################
# Creating directory.
cd /tmp
for i in `cat server.list`
do
echo "Creating directory at server= $i"
ssh $i "mkdir /home/user1/TST"
done
# Copying file..
for i in `cat server.list`
do
scp /tmp/test.tar $i:/home/user1/TST
done
#######################################

Note: You need to provide the server's password while ssh/scp loggin in , if you donot have a ssh-keygen set from server1.
If ssh-keygen set from server1 , the script will prompt for password.

Cheers ,
Raj.D



" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: need a script to copy a file to 5 servers

Hi ,

Pls put a echo $i , before scp , so that u can come to know which server password need to provide.

i.e

#!/usr/bin/ksh
# copying server1:/tmp/test.tar to server2,3,4,5,6.. /home/user1/TST/
########################################
# Creating directory.
cd /tmp
for i in `cat server.list`
do
echo "Creating directory at server= $i"
ssh $i "mkdir /home/user1/TST"
done
# Copying file..
for i in `cat server.list`
do
echo " Server = $i "
scp /tmp/test.tar $i:/home/user1/TST
done
#######################################

If ssh-keygen is set , it will not prompt for password.

Cheers,
Raj.D

" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: need a script to copy a file to 5 servers

Also forgot to tell that server.list will have all the servers name .

like :
server2
server3
server4

------------
" If u think u can , If u think u cannot , - You are always Right . "