We want to create a report with MD5 checks between an tar archive on tape and the files on disk. I created a script that should do this, but it works correct using a tar file, but it failes when using a tar on tape. The tar was written with gnu tar to tape.
use strict;
use warnings;
use Archive::Tar;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $tarfile = '/dev/rmt/1';
my $iter = Archive::Tar->iter( $tarfile, 1, {md5 => 1} );
print "------------ TAR MD5 ----------- ----------- FILE MD5 ----------- ----- File -----\n";
while( my $f = $iter->() ) {
if ($f->is_file != 0) {
my $tarMd5 = md5_hex( $f->get_content);
my $filename = $f->full_path;
my $fileMd5 = '';
if (-e $filename) {
open(HANDLE, "<", $filename);
$fileMd5 = md5_hex(<HANDLE>);
} else {
$fileMd5 = "!!!!!!! FILE IS MISSING !!!!!!!!";
}
if ($tarMd5 eq $fileMd5) {
print "$tarMd5 <--> $fileMd5 --> $filename\n";
} else {
print "$tarMd5 ><>< $fileMd5 --> $filename\n";
}
}
}
As said it works correct when using a file based tar file, but when using a tar on tape we get the error:
Use of uninitialized value in subroutine entry at check_archive.pl line 12. Can't use string ("") as a subroutine ref while "strict refs" in use at check_archive.pl line 12. my $f is not defined.