Operating System - HP-UX
1832997 Members
2335 Online
110048 Solutions
New Discussion

Re: copy files on many hosts

 
SOLVED
Go to solution
Kgreen
Advisor

copy files on many hosts

Hi I have about 50 new servers. I have to copy one file across these 50 servers. I have an oper account that has same password on all 50 servers.How can I copy files from one server to rest 49 servers, without going and editing the rhosts, hosts.equi files on the rest 49 servers..
7 REPLIES 7
Patrick Wallek
Honored Contributor
Solution

Re: copy files on many hosts

Does the oper account have ftp access?

If so do something like this:

1) Create a file with the names of the other 49 servers.

# cat server_list
server1
server2
server3

2) Create a script that will read server_list and ftp your file to them.

#!/usr/bin/sh

SOURCE=/dir/sourc/file
DESTDIR=/dir/dest
DESTFILE=file1

for NAME in $(cat server_list)
do
ftp -inv ${NAME} << EOF
user oper password
bin
cd ${DESTDIR}
put ${SOURCE} ${DESTFILE}
bye
EOF
done
A. Clay Stephenson
Acclaimed Contributor

Re: copy files on many hosts

In that case, ftp would probably be your best bet although I really consider doing the front-end work for rcp or ssh a case of pay me now or pay me later. Anyway, we can leverage Perl's Net::FTP module to do your stuff --- and all you need to know is a little shell scripting.

#!/usr/bin/sh
HOSTS="mickey minnie donald pluto"
for HOST in ${HOSTS}
do
ftpput.pl -h ${HOST} -l oper -p secret -B -d /xxx/yyy myfile
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Transfer to ${HOST} ok."
else
echo "Transfer to ${HOST} failed; status ${STAT}" >&2
fi
done
---------------------------------------

If you will create a .netrc file on your local box then there is no ned for the -p password. Invoke the attached script as "ftpput.pl -u" for full usage.

If it ain't broke, I can fix that.
Kgreen
Advisor

Re: copy files on many hosts

thank you guys that works
Kgreen
Advisor

Re: copy files on many hosts

Guys what if I want to execute some unix commands on the 49 hosts and then exit. I know need to improve on my scripting.
Yang Qin_1
Honored Contributor

Re: copy files on many hosts

You can run rexec as oper.

Logon to server1 and in oper's $HOME create a .netrc file with format:

machine server2 login oper password mypass
machine server3 login oper password mypass
machine server4 login oper password mypass

machine server49 login oper password mypass

after you create the file run "chmod 400 .netrc

Create a script:

#/usr/bin/ksh

for svr in `cat $HOME/.netrc|awk '{print $2}'`
do
rexec $svr ls -l
done

exit

Note: you only need to create .netrc on server1 and you can only run rexec from server1

with the same .netrc, when you run ftp to the other 49 servers, system will not ask you for the password.
Maxim Yakimenko
Super Advisor

Re: copy files on many hosts

And I would assume the use of ssh - it is much more secure then rexec
Ralph Grothe
Honored Contributor

Re: copy files on many hosts

Yes, more secure in two ways.
Firstly no passwords for authorization are transmitted in clear.
Secondly the whole data transfer is also encrypted.
This of course comes at a price of a little overhead which should reduce the throughput compared to the r* commands.
Besides, the usage is very similar to remsh.
Madness, thy name is system administration