Operating System - HP-UX
1831547 Members
3761 Online
110025 Solutions
New Discussion

edit hosts file on multiple servers without NIS

 
SOLVED
Go to solution
Petr Simik_1
Valued Contributor

edit hosts file on multiple servers without NIS

I have relocated server and now I have new IP adress on it. I wat to update hosts file on other 40servers. I don't use NIS. Typing one-by-one is the possibility, but I am looking for some more sofisticated way.

something like

for i in `cat serverlist`
do
remsh 'edit .... file /by scenario'
done

THanks for any Ideas
7 REPLIES 7
John Dvorchak
Honored Contributor
Solution

Re: edit hosts file on multiple servers without NIS

I would think that if you have any more that about two servers you would want to implement DNS and avoid all of these types of issues. But to answer your question:

for i in `cat serverlist`
do
remsh $i "sed 's/old.add/new.add/g /etc/hosts'"
done


I haven't tried this but it should work. Do yourself a favor and implement DNS. It is easy quick with hosts_to_named
If it has wheels or a skirt, you can't afford it.
John Dvorchak
Honored Contributor

Re: edit hosts file on multiple servers without NIS

Ok my mistake, you can't use sed you have to use ed. So change the edit line to:

remsh $i " ed '(1,$) g/old.address/new.address' /etc/hosts"
If it has wheels or a skirt, you can't afford it.
Dietmar Konermann
Honored Contributor

Re: edit hosts file on multiple servers without NIS

IPOLD=xxx
IPNEW=yyy

for host in $( remsh $host "cp /etc/hosts /etc/hosts.org && sed s%$IPOLD%$IPNEW%g < /etc/hosts.org >/etc/hosts"
done
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
S.K. Chan
Honored Contributor

Re: edit hosts file on multiple servers without NIS

One way is ..

for i in `cat serverlist`
do
remsh $i "sed 's///g' /etc/hosts>/etc/hosts.new;mv /etc/hosts /etc/hosts.old;mv /etc/hosts.new /etc/hosts;chown root:sys /etc/hosts;chmod 444 /etc/hosts"
done

A good tool to distribute files to clients that you should seriously consider using is "rsync". It's easy to implement and is based on rcp plus some added security option. I use it alot to synchoronize some files between machines.
http://samba.anu.edu.au/rsync/
Michael Steele_2
Honored Contributor

Re: edit hosts file on multiple servers without NIS

Pete Randall
Outstanding Contributor

Re: edit hosts file on multiple servers without NIS

Just edit the hosts file on one server and then copy it to others with a script like this:

for SERVER in `cat hostlist`
do
if [ $SERVER != $HOST ]
then
echo $SERVER
rcp -p $FILENAME $SERVER:$FILENAME
fi
done


Pete

Pete
John Dvorchak
Honored Contributor

Re: edit hosts file on multiple servers without NIS

Ok I'll get this command correct yet.

sed s/132.201.90.73/132.201.90.770/g < /etc/hosts > /etc/hosts.new; cat /etc/hosts.new > /etc/hosts;

If it has wheels or a skirt, you can't afford it.