Operating System - HP-UX
1753460 Members
4715 Online
108794 Solutions
New Discussion юеВ

/etc/hosts need to be in correct format in multiple hosts.

 
samay_hcl
Advisor

/etc/hosts need to be in correct format in multiple hosts.

Hello Experts,
I have an issue that i need to correct /etc/hosts file on around 800 servers.

what I want to do is I am mentioning as follows :

Current entry in /etc/hosts file is below:

Ip_address hostname FQDN

and some servers have entry as below

Ip_address hostname

I want to make it as below on all the server

Ip_address FQDN hostname

I have one jump server from where I am able to ldo ssh on all the servers without giving any passsword.

Please help....

4 REPLIES 4
samay_hcl
Advisor

Re: /etc/hosts need to be in correct format in multiple hosts.

Please let me know if you have any shell script or perl script to do this activity.
Dennis Handly
Acclaimed Contributor

Re: /etc/hosts need to be in correct format in multiple hosts.

>I have one jump server from where I am able to do ssh on all the servers without giving any password.

Ideally you would first copy the script to each machine. Then you could invoke ssh to fix each machine.

You could write an awk script to read each line of /etc/hosts and if there are only two fields and the first isn't "#", then you can invoke:
nslookup Ip_address | grep "Name:"
and get the second field as the FQDN.
rick jones
Honored Contributor

Re: /etc/hosts need to be in correct format in multiple hosts.

The difficulty you are experiencing is one of the reasons DNS was invended so many years ago. Soooo, why is it you have 800 systems relying on a /etc/hosts entry for a specific hostname rather than using DNS?
there is no rest for the wicked yet the virtuous have no pillows
Kapil Jha
Honored Contributor

Re: /etc/hosts need to be in correct format in multiple hosts.

Correct!!
Its better if you use DNS anways even if you put the entries as
IP FQDN Hostname rather than
IP Hostname FQDN

Its same right there is not issue with this.
And if you want to use DNS check nsswitch.conf file and change the
hosts: line

thats would be feasible I suppoe.

BR,
Kapil+
I am in this small bowl, I wane see the real world......