Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Find match in two diff files at tim

Original Message
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:

file1.abc format:

Fsdfsdf kkldfsd
Component sunsolaris
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd

Fsdfsdf kkldfsd
Component hpunix
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd

Fsdfsdf kkldfsd
Component linux
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd


Following is file2.abc (Remote server – server 2)

Fsdfsdf kkldfsd
Component sunsolaris
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd

Fsdfsdf kkldfsd
Component winxp
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd

Fsdfsdf kkldfsd
Component hpunix
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd

Fsdfsdf kkldfsd
Component winxp
Sdfsdfs dfdsfds
Sdfsdf sdfsdf
Sdfsdf ertyertre
Sdfsdf hfdghdfgd


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.


Thanks.


Report Offensive Message For Removal


Response Number 1
Name: FishMonger
Date: March 6, 2008 at 23:41:33 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 2
Name: FishMonger
Date: March 6, 2008 at 23:48:35 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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.

Report Offensive Follow Up For Removal

Response Number 3
Name: rayman777
Date: March 7, 2008 at 06:19:40 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
No, I am not ricky007. I did not find exact same request. Was it resolved?
I am thinking how do I do it. I just need some guide. Thanks.

Report Offensive Follow Up For Removal

Response Number 4
Name: FishMonger
Date: March 7, 2008 at 09:41:55 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 5
Name: rayman777
Date: March 7, 2008 at 13:45:52 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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.

#Building arrays for filenames of server1


@server1_files = (
‘file1.abc’,
‘file1.bcd’,
‘file1.dfg’,
‘file1.ghi’,
‘file1.ijk’,
‘file1.klm’,
‘file1.mno’,
‘file1.opq’,
‘file1.qrs,
‘file1.stu’,
‘file1.uvw’,
‘file1.wxy’,
‘fle1.yza’);

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.

while ( my @server1_files = <file1.*> ) {
my %components_names;
open(FILE, @server1_files) || die $!;
while (<FILE>) {
chomp;
$components_names{$_}++; # create hash
}
foreach my $components_names (keys % components_names) {
if ($components_names {$ components_names } > 1) {
print "$ server1_files duplicated values: $components_names \n";
}
}
}


Report Offensive Follow Up For Removal


Response Number 6
Name: FishMonger
Date: March 7, 2008 at 14:38:48 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
Since you need to hard code the file to server relations, server1_files should be a hash instead of an array.
%server1_files = (
‘file1.abc’ => 'server2',
‘file1.bcd’ => 'server3',
‘file1.dfg’ => 'server4',
‘file1.ghi’ => 'server5',
‘file1.ijk’ => 'server6',
‘file1.klm’ => 'server7',
‘file1.mno’ => 'server8',
‘file1.opq’ => 'server9',
‘file1.qrs' => 'server10',
‘file1.stu’ => 'server11',
‘file1.uvw’ => 'server12',
‘file1.wxy’ => 'server13',
‘file1.yza’ => 'server14',
);

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
}


http://search.cpan.org/~nwiger/File...

BTW, please wrap your code in the html pre tags so that the code indentation is preserved.


Report Offensive Follow Up For Removal

Response Number 7
Name: rayman777
Date: March 7, 2008 at 16:03:01 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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);



Report Offensive Follow Up For Removal

Response Number 8
Name: FishMonger
Date: March 7, 2008 at 18:37:51 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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.

Report Offensive Follow Up For Removal

Response Number 9
Name: ricky007
Date: March 10, 2008 at 08:55:17 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
Can I hardcode the login and passwd instead?

Also %server1_files hash I need to indicate where the files are located
(exp/usr/mtr/)?

Please assist.

Thanks


Report Offensive Follow Up For Removal

Response Number 10
Name: ricky007
Date: March 13, 2008 at 06:30:13 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
Hello Fishmonger, have you given up on me?

Report Offensive Follow Up For Removal

Response Number 11
Name: FishMonger
Date: March 13, 2008 at 22:58:30 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 12
Name: ricky007
Date: March 18, 2008 at 07:28:32 Pacific
Subject: Find match in two diff files at tim
Reply: (edit)
Instead we should use:

use Net::SCP::Expect;


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Find match in two diff files at tim

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12

help mandriva install last straw!

Icon Scaling in Explorer Bar


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

All content ©1996-2007 Computing.Net, LLC