Below is a script I have been working on that verifies if another script has 
created the MD5 hash file correctly. The
below works with

            if ( $checkFile = $file )

 but not if

            if ( $checkFile != $file )

 

and I do not understand why that is.

 

Can someone explain what I am doing wrong?

 

Thanks 

Tony

 

 

 

#!/usr/bin/perl

# AUTHOR Tony Heal - [EMAIL PROTECTED]

use strict;

use warnings;

use Digest::MD5 qw(md5);

use Sys::Hostname;

 

my $filesize;

my $testPrefix = "200708040030";

 

#verify the MD5 hash use Digest::MD5  my $digest = file_md5($file); if orig md5 
== new then good

my $host = hostname;

open(MD5FILE, "</opt/backup/$testPrefix-$host-md5-checksums.txt") or die "Can 
not open MD5-checksum file. $!";

my %MD5HASH;

while(<MD5FILE>)

{

    if ( /^([0-9A-Za-z]*?)(\s*)([0-9]{12}-(.)*)/ )

        {

                my $key = $1;

                my $value = $3;

                $key =~ s/^(\s+)(.*?)(\s+)$/$2/;

                $value =~ s/^(\s+)(.*?)(\s+)$/$2/;

                $MD5HASH{$key} = $value;

        }

}

close MD5FILE;

 

opendir(BACKUP, "/opt/backup" ) or die "Can not open directory 
'/opt/epace/backup/'. $!";

my @md5FileList = readdir(BACKUP);

closedir BACKUP;

 

while (<@md5FileList>)

{

    my $file = $_;

    if ( $file =~ /$testPrefix/ )

    {

            my $digest = md5 $file;

            my $checkFile = $MD5HASH{$digest};

            if ( $checkFile = $file )

            {

                print "$file has a good MD5 match\n";

            }

    }

}

 

/opt/backup/$testPrefix-$host-md5-checksums.txt:

 

f522c8928669f423c64fd63e7dc58f4a  200708040030-dump

5e7980aebafac3023bce54093978db5f  200708040030-sample-dump

c02c0b360a51e7af704648431c367415  200708040030-conf.tar.gz

0598e857f3e2575fb4a9a542429f347b  200708040030-reports.tar.gz

0a91aab9779829118f29e8076ada2264  200708040030-logs.tar.gz

a9cf42eff4ab11a200e7891f9a9e95cb  200708040030-scripts.tar.gz

6d060f40e0b3bd3309ec93b23799254f  200708040030-custom.tar.gz

acd9d62f1bd034ff4381a76b10f1ac0a  200708040030-client-info.tar.gz

7a321bff85167b425b3b3c3b4f2f728f  200708040030-crons.tar.gz

 

Reply via email to