-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcheckMD5.pl
More file actions
executable file
·46 lines (40 loc) · 800 Bytes
/
checkMD5.pl
File metadata and controls
executable file
·46 lines (40 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env perl
# usage: perl checkMD5.pl {file}
use strict;
use Getopt::Std;
our($opt_f);
getopts('f:');
my @files;
if (defined $opt_f) {
open IN, "<$opt_f";
@files = <IN>;
close IN;
} else {
@files = @ARGV;
}
my $passes;
my $fails;
foreach (@files) {
chomp;
my $md5file = $_ . ".md5";
if (! -f $md5file) {
print "$md5file does not exist\n";
next;
}
print "$_: ";
chomp(my $md5 = `cut -f1 -d' ' $md5file`);
chomp(my $newMd5 = `md5 $_ | sed 's/.*= //'`);
if ($md5 eq $newMd5) {
print "PASS ($md5)\n";
$passes++;
} else {
print "FAIL\n\t$md5 != $newMd5\n";
$fails++;
}
}
if ($fails) {
print "$passes / " . scalar @ARGV . " PASSED\n";
exit 1;
} else {
print "ALL PASSED\n";
}