-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha
28 lines (27 loc) · 884 Bytes
/
sha
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
use strict; use warnings;
use File::Find::Rule;
use Digest::SHA;
##########################
# USAGE
my ($target, $shalog) = @ARGV;
if (not defined $target) {die "usage: DIR TO SCAN ARGV[0] & shalog argv[1]"; }
if (not defined $shalog) {die "usage: dir to scan argv[0] & SHALOG ARGV[1]"; }
open(my $lfh, '>>', $shalog) or die "couldn't open shalog argv[1]";
############################
# FIND FILES RECURSIVE
my $rule = File::Find::Rule->file()->start($target);
my %response;
while(defined(my $file = $rule->match)) {
my ($sha) = file_digest($file) or die "couldn't sha $file";
$response{$file} = $sha;
}
while (my ($key, $value) = each %response)
{ print $lfh "$value: $key\n"; }
########################
# SHA FN
sub file_digest {
my ($filename) = @_;
my $digest = Digest::SHA->new(256);
$digest->addfile($filename, "b");
return $digest->hexdigest();
}