1

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.

Ronald
  • 31
  • 4
  • Put `print "OBJ:[$f]\n";` inside `while`. – mpapec Sep 03 '14 at 08:42
  • It never reaches the inside of the while. adding the line does not show any output. We added `$Archive::Tar::WARN = 1; $Archive::Tar::DO_NOT_USE_PREFIX=1;` But at the moment we don't get the error anymore, but it still does not read the tape. – Ronald Sep 03 '14 at 14:23

1 Answers1

0

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.

if ($f && $f->is_file != 0) {## NOT AN IMPORTANT WARNING...

...

if (-e $filename) { ## CHECK IF FILE EXISTS
    local $/="";    ## <= JUST ADD THIS FOR INSTANT OUTPUT (NO BUFFER)
    open(HANDLE, "<", $filename); ## CREATE A FILE HANDLE TO READ A FILE
    $fileMd5 = md5_hex(<HANDLE>); ## SEND HANDLE TO THE MD5 FUNCTION
}

...

MuchiProds
  • 11
  • 3
  • 1
    Could you please [edit] in somewhat more of an explanation of why this code answers the question? Code-only answers are [discouraged](http://meta.stackexchange.com/q/148272/274165), because they don't teach the solution. – Nathan Tuggy Jun 15 '15 at 01:33