-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_SCRUB.pl
41 lines (41 loc) · 1.16 KB
/
a_SCRUB.pl
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
#!/usr/local/bin/perl
use strict; use warnings;
use Digest::SHA;
#######################################
# SCRUB - output sha-stamped-lists
#######################################
my ($node, $pool, $log)=@ARGV;
die "ARG1 node ARG2 location ARG3 log" if (!defined $log);
$pool =~ %/\z%%;
my $date = time;
my $stamp = $node.'_'.$date;
my $error = $log.'_ERROR';
#######################################
open(my $efh, '>>', $error);
open(my $nfh, '>', $new);
opendir(my $dh, $dir) or die "FAIL opendir $dir";
#######################################
my @list = readdir $dh;
closedir $dh; chomp @list;
#######################################
for (@list)
{
my $file = $_;
$file =~ $pool.'/'.$file;
my $sha=file_digest($file) or die "FAIL sha $file";
#######################################
$file =~ s/.*\///;
#######################################
if ($sha ne $file)
{ print $efh "FAIL sha $node $file\n"; next; }
#######################################
print $nfh "$file $stamp\n";
}
#######################################
sub file_digest
{
my ($filename)=@_;
my $digest=Digest::SHA->new(256);
$digest->addfile($filename, "b");
return $digest->hexdigest();
}