Name: rayman777 Date: March 6, 2008 at 22:13:17 Pacific Subject: Find match in two diff files at tim OS: Solaris CPU/Ram: SUN Model/Manufacturer: SUN
Comment:
Perl Guru….
I need to compare two diff file (file1.abc will locate in current server and file2.abc will locate in remote server), basically the script will look for match in both file and only will send out email if there is no match and also give me list of unmatch and dups as well.
So here is the logic how the script will work.
The script will reside in Server1. Server 1 has 13 different files like:
file1.abc …………..>compare with remote server (server 2) file2.abc file1.bcd…………..>compare with remote server (server 3) file2.abc file1.dfg …………..>compare with remote server (server 4) file2.abc file1.ghi…………..>compare with remote server (server 5) file2.abc file1.ijk…………..>compare with remote server (server 6) file2.abc file1.klm…………..>compare with remote server (server 7) file2.abc file1.mno…………..>compare with remote server (server 8) file2.abc file1.opq…………..>compare with remote server (server 9) file2.abc file1.qrs…………..>compare with remote server (server 10) file2.abc file1.stu…………..>compare with remote server (server 11) file2.abc file1.uvw …………..>compare with remote server (server 12) file2.abc file1.wxy…………..>compare with remote server (server 13) file2.abc file1.yza…………..>compare with remote server (server 14) file2.abc
(The file names before extension are the same in Server1, but all filename are same in remote servers)
Now I need to compare file1.abc with remote server (Server 2) filename (file2.abc) (/xxx/xyx/mns/file2.abc). The script need to compare only with component name In this example sunsoloaris, hpunix, linux.
All of the file has same format in both file types. Format is like the following:
Output will be in an email: (If exact match of Component found don’t send email.) If exact match of Component not found send email. E-mail should indicate: Component linux not found in file2.abc in remote server (server 2) Multiple entries of Component winxp found in file2.abc in remote server (server 2)
To get date from remote server login and passwd will be required.
I'm one of the few Perl programmers here, so I guess I'm the resident "Perl Guru". I'd be happy to assist you with your script, but I'm not interested in doing the whole script for you.
Have you starting working on the script? If so, post your code and specific question(s) on the part(s) that's giving you problems.
BTW, do you also use the username ricky007? That user has almost the exact same request, which would indicate that either you are ricky007 or that you both are taking the same Perl programming class.
What determines that file1.abc needs to be compared with file2.abc on server2 and not server3 or server4?
What connection method do you use between the servers; NFS mount, telnet, ftp, ssh?
1) Build an array or hash of the file names on Server1.
2) As you loop through that array/hash open the file and build a hash of the component names. The value of each hash key could be a counter.
3) Within each of those loops, access/open the remote file and increment the counter in the "component" hash for each component found in the remote file.
4) Loop through the component hash and any value that's greater than 1 tells you that it's in both files.
I've left out a lot of details, but that should get you started.
Thank you very much, I am still struggling. Please see below what I got so far:
Q. What determines that file1.abc needs to be compared with file2.abc on server2 and not server3 or server4? What connection method do you use between the servers; NFS mount, telnet, ftp, ssh?
A. I have to hardcode file1.abc needs to be compared with file2.abc server2 and so on..... That is a direct relationship, it will not go to any other server. Connection method will be ssh.
1) Build an array or hash of the file names on Server1.
foreach my $file ( keys %server1_files ) { my %components;
open my $FILE, '<', $file or die $!; while ( my line = <$FILE> ) { chomp $line; next unless $line =~ /Component (.*)/; $components{$1}++; } close $FILE;
# I'm skipping the needed ssh code
# Now, you need to open the remote file # and do another while loop like before. # I'd probably look into using File::Remote # to access the other files, which handles # the ssh stuff in the background }
Thank you, here what I have compiled but I am confused how to combine ssh to remote server and then open the file from that remote server:
#Special :replace tag to overload Perl builtins!
use File::Remote qw(:replace); # special :replace tag
# Read from a remote file located in remote server, connect to remote server via ssh login
my $secure = File::Remote->new(rsh => :’/export/home/rf/filename’; open(REMOTE, "server:/export/home/rf/filename") or die $!; while ( my line = <REMOTE> ) { chomp $line; next unless $line =~ /Component (.*)/; $components{$1}++; } close (REMOTE);
Actually, I haven't yet used the File::Remote module, so I'll need to do some testing of my own. My assumption is that you'll need to setup your ssh keys correctly (i.e., putting your public key in the authorized_keys file) so that you can login without being prompted for your password.
No, I haven't given up on you. ;) I've been tied up on several important projects at work and haven't had much free time.
I'm not sure if the File::Remote module supports plain text password authentication, but there are other modules to choose from. It's late here, so I post again tomorrow with 1 or 2 possible options.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE