File Compare in PERL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Compare in PERL
# 1  
Old 05-01-2006
File Compare in PERL

I need to look at a log file every half hour or so to make sure that some activity is going on there. I thought I would write a quick PERL script that would copy the current log file to the temp directory, compare it to the previous log file (from 30 minutes ago) and exit with an error status if the two files are identical. Here is what I threw together.

The log file (for today) is named "log_AutoIndexService_20060501.txt".
It lives in C:\autoindex.
This script will be excuted every thirty minutes, and will page me if it returns an error result code.


=======================
$log_dir = "c:\\autoindex";
$month = substr(`date /T`,4,2);
$year = substr(`date /T`,10,4);
$day = substr(`date /T`,7,2);
$full_date = "$year$month$day";
$file_name = "log_AutoIndexService_$full_date.txt";

`copy $log_dir\\"$file_name" c:\\temp\\AutoIndexService_log.tmp`;

$diff = `fc c:\\temp\\AutoIndexService_log.tmp c:\\temp\\AutoIndexService_log.txt`;

`del c:\\temp\\AutoIndexService_log.txt`;

`ren c:\\temp\\AutoIndexService_log.tmp AutoIndexService_log.txt`;

if( $diff eq "" ) {
exit 1;
}

=======================

So far, the script is running, the files are being copied and removed, but I am not getting paged when the two files are identical. Is my file compare logic wrong, or the way I am using the $diff variable?

Any help would be appreciated.
# 2  
Old 05-01-2006
Quote:
Originally Posted by Cbish68
$diff = `fc c:\\temp\\AutoIndexService_log.tmp c:\\temp\\AutoIndexService_log.txt`;
Backticks returns the standard output of the command executed, not the return value. If the command does not generate any output, it is understandable that a test on $diff is empty.

See perlvar and look for the documentation on $? for a treatment on how to get the return value.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two lists with perl

Hi everybody! I'm trying to delete some elements from a list with two elements on each row agreeing with the elements in another list. Pratically I want a perl script able to take each element of the second list (that is a single column list), compare it with both elements of each row from the... (3 Replies)
Discussion started by: gabrysfe
3 Replies

2. Shell Programming and Scripting

perl: compare two arrays

Hi friends, I want to compare two arrays and find matched one using perl? Also, I want to delete unmatched one. Plz suggest me solution (1 Reply)
Discussion started by: Renesh
1 Replies

3. Shell Programming and Scripting

compare two value in array - Perl

Hi, I just wondering if I want to compare previous value to next value if it same count + 1 if not doesn't count how do we compare in Perl? Thank (2 Replies)
Discussion started by: guidely
2 Replies

4. Shell Programming and Scripting

Perl Compare 2 Arrays

Hello, Consider the following 2 arrays: Array1 = qw(Fa0/0 Fa0/1 Fa0/2 Fa0/3); Array1 = qw(Fa0/1 Fa0/2 Fa0/3 Fa0/4); I want to compare the following 2 arrays as follows: Take specific action when elements of Array1 that doesn't exist in Array2 (in my example: Fa0/0). Take another... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

5. UNIX for Dummies Questions & Answers

SOLVED: Text file compare using perl

I have two text file.... One text file contain in this format...... keyvalue.txt \SUM\SUM_cam.c \SUM\SUM_cam.h \SUM\SUM_command.c \SUM\SUM_command.h \SUM\SUM_dab.c \SUM\SUM_dmb.c \SUM\SUM_eventHandler.h \SUM\SUM_eventHandler_dab.c \SUM\SUM_eventHandler_dmb.c ... (6 Replies)
Discussion started by: suvenduperl
6 Replies

6. Shell Programming and Scripting

compare 5% and 40% in perl

hi everyone, how to compare 5% and 40% in perl, which one if bigger? Thanks (6 Replies)
Discussion started by: jimmy_y
6 Replies

7. Shell Programming and Scripting

Compare arrays (perl)

Hi, my first post here! Description of my problem: I have one txt-file with six rows and each row contains seven numbers seperated with whitespaces. I want to: Compare one array with seven numbers with each row of numbers in the txt-file. I have managed to compare one array with... (6 Replies)
Discussion started by: mjoh
6 Replies

8. Shell Programming and Scripting

compare 2 arrays in perl

Hi Im supposed to compare lines in a file : KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 1045 S KQLESEGRS 0.669 PKC YES KB0005 1045 S KQLESEGRS 0.880 unsp YES KB204320 1019 T IFVATVPVI 0.699 PKC YES ... (7 Replies)
Discussion started by: karla
7 Replies

9. Shell Programming and Scripting

PERL - copy fiel contents to array then compare against other file

Basically to illuminate i want to take a file with mutliple lines, C:\searching4theseletters.txt a b c Read this into an array @ARRAY and then use this to compare against another file C:\inputletters.txt b o a c n a (9 Replies)
Discussion started by: bradleykins
9 Replies

10. Shell Programming and Scripting

Perl - Compare 2 Arrays

Hi all, I have the following script where the contents of file1 and file2 would be something like this: file1: 56790,0,0,100998765 89756,0,0,100567876 867645,1,3,678777654 file2: 56790,0,0,100998765 65776,0,0,4766457890 +5896,0,0,675489876 What I then want to do is check if... (4 Replies)
Discussion started by: Donkey25
4 Replies
Login or Register to Ask a Question