- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Howto merge 2 differrent /etc/hosts files?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:29 AM
тАО11-11-2003 03:29 AM
I want to merge the /etc/hosts files caoming from 2 different hosts.
How I can do it?
Regards...
PSS
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:30 AM
тАО11-11-2003 03:30 AM
Re: Howto merge 2 differrent /etc/hosts files?
Have a look at the sort man page, particularly the merge section. That should get you started.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:35 AM
тАО11-11-2003 03:35 AM
Re: Howto merge 2 differrent /etc/hosts files?
I'd cp /etc/hosts > temp
then the second
cp /etc/hosts >> temp
Append mode.
I might try sort, but in the end I'm going to have to go through the files manually and look for conflicts.
For sure, get rid of the second loopback line.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:38 AM
тАО11-11-2003 03:38 AM
Re: Howto merge 2 differrent /etc/hosts files?
-USA..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:39 AM
тАО11-11-2003 03:39 AM
Re: Howto merge 2 differrent /etc/hosts files?
- get both host files on the same system. Call them host1 and host2
- merge them like this:
cat host1> tmphost
cat host2>> tmphost
- visually verify the merge:
pg tmphost
- filter the merged file:
cat tmphost|sort|uniq >tmp2host
- visually verify the new file:
pg tmp2host
Now it should be a simple job of removing any remaining duplicates using vi. When done you can copy the file to /etc/hosts and HUP the appropriate services or reboot.
HTH
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:40 AM
тАО11-11-2003 03:40 AM
Solutioncat /etc/hosts >/tmp/newhosts
cat
then;
cat /tmp/newhosts | sort -u > /etc/hosts
(Make a backup of /etc/hosts first just in case). The sort -u means remove all duplicates. Then check the hostname for your server has the correct IP in your new hosts file and that should do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:45 AM
тАО11-11-2003 03:45 AM
Re: Howto merge 2 differrent /etc/hosts files?
Don't worry too much about the possible duplicates, but be aware that only the 1st one will be read. Also, a small performance gain is possible if you have the most often used entries at the top.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 03:45 AM
тАО11-11-2003 03:45 AM
Re: Howto merge 2 differrent /etc/hosts files?
I'm assuming you want to remove duplicate items from the two files.
Part of it depends on if you want to preserve comments beyond the top of the files.
If you dont then you can run the attached script as follows:
combine input1 input2 output
It will keep the comments from the top of the FIRST input file specified. The final assumption is that you dont have files that start with ".useme" in the directory where you are running the script.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2003 06:49 AM
тАО11-11-2003 06:49 AM
Re: Howto merge 2 differrent /etc/hosts files?
while(<>) {
next if /^#/ or /^$/;
@a=split('\s+',$_);
$hold{$a[0]}{$a[$i]}=1 for $i (1..$#a);
}
foreach $ip (sort keys %hold) {
print "$ip\t",join(" ",keys %{$hold{$ip}}),"\n";
}
perl aboveprogram hostfile1 hostfile2 >newhostfile
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2003 05:56 AM
тАО11-12-2003 05:56 AM
Re: Howto merge 2 differrent /etc/hosts files?
1. grep "^#" /etc/hosts > newhosts
2. grep -v "^#" /tmp/hosts /etc/hosts|sort|uniq >> newhosts
3. vi newhosts
put localhost below comments.
put system below localhost.
fix problem childern like if host are not duplicate host names and ip address that did compare from the sort uniq.
4. cp /etc/hosts /etc/hosts.rl
5. cp newhosts /etc/hosts
Rory