Operating System - HP-UX
1834039 Members
2202 Online
110063 Solutions
New Discussion

Comparing more than two files

 
SOLVED
Go to solution
Party
Occasional Contributor

Comparing more than two files

Hi All

Can anybody help me in compareing
services
sendmail.cf
nsswitch.conf
/etc/profile
/root/.forward
/etc/shells
sudoers
syslog.conf
/root/.profile

these files in more than 80 servers

Thanks
Binu
7 REPLIES 7
Jean-Luc Oudart
Honored Contributor

Re: Comparing more than two files

Hi Binu,

Do you want to compare each of them against a model / baseline
or do you want to compare against each of them.
In the later, what would you do with the results ?

Jean-Luc
fiat lux
Party
Occasional Contributor

Re: Comparing more than two files

Hi Jean

My requirement is to check whether the above
files are similar in 80 diffrent servers

Thanks
Binu
Jean-Luc Oudart
Honored Contributor

Re: Comparing more than two files

Hi,

ok you want to check all of them against all others...

I think this will involve a fair amount of scripting.
Once you have the script right for one (say /etc/services), you can extent to other files.

You will have to copy all the files (qualified with hostname) in a central location, then run the compare script.

Also, you will have to make some choice
e.g
- ignore comment lines
- ignore blank lines
- Is the order important ? (the files may be different eventhough contents is the same !), if not re-order te file prior to comparison, ...

Regards
Jean-Luc
fiat lux
Muthukumar_5
Honored Contributor

Re: Comparing more than two files

We can compare two same files with diff command.

If you want to compare each line of unique files from 80 server then, scripting needed here.

diff -Nur will give difference there.

Easy to suggest when don't know about the problem!
Rodney Hills
Honored Contributor
Solution

Re: Comparing more than two files

Here is a perl script to checksum each file on each host and print out which files are the same on each host.

Each file is pulled to /tmp. The checksum is done after the file has been simplified (ignore blank lines, ignore comments, squeeze multiple blanks, etc).

The print out will list each file followed by the hosts that have the same checksums.

HTH

-- Rod Hills

@hosts=qw{server1 server2 server3};
@files=qw{/etc/services /etc/sendmail.cf /etc/nsswitch.conf /etc/profile /root/.forward /etc/shells sudoers syslog.conf /root/.profile};
foreach $host (@hosts) {
foreach $file (@files) {
system("scp -q $host:$file /tmp/file1");
$cksum=0;
open(INP," while() {
chomp;
next if /^$/; # Skip blank lines
next if /^#/; # Skip comments
s/\s+/ /g; # Squeeze multiple blanks
y/A-Z/a-z/; # make line all lowercase
$cksum+=unpack("%32a*",$_);
}
push(@{%hold{$file}{$cksum}},$host);
}
}
foreach $file (sort keys %hold) {
print $file,"\n";
foreach $cksum (keys %{$hold{$file}}) {
print " Match:";
foreach $host (sort @{$hold{$file}{$cksum}}) {
print " ",$host;
}
print "\n";
}
}
There be dragons...
Party
Occasional Contributor

Re: Comparing more than two files

Hi
Thank you very much for your valueable input
Can you help me in clarifying some more doubts
1)Can we find out which lines in the files have diffrences
2)Do we have to ftp individual files in a single server for comaprison if not how the authentication happens
3)Can we excecute the script from a single server which collects the files from all the servers and gives the comparison output

Thanks
Binu
Rodney Hills
Honored Contributor

Re: Comparing more than two files

In my script above, I am fetching each file from each host. I am not using ftp, but rather "scp" which is part of openssh. Openssh is available from HP software depot. The benefit of scp is that if configured correctly, you don't need to give a password, plus the data is secured as it is transfered over the network.

My script is designed to run from a single host.

My script only indicates which files are the same. To find individual line differences, you would need to define a "base" version of each file and compare against it. My perl script could be modified to do this by stripping out the checksumming and having it call the "diff" command to do the testing.

HTH

-- Rod Hills
There be dragons...