perl script help

Hello Experts:

I am looking for multi-threaded script to parse through the NAS folders and subfolders .. and get checksum values of all files

Sample output
Path, File, checksumvalue

Using this script - doesn't work

#!/usr/local/bin/perl
use strict;
use warnings;
use File::Find ();
use Cwd ();

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;

my $cwd = Cwd::cwd();

# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/directory1');
exit;

sub wanted {
    return unless (-f $_);
    my $cksum = `cksum $name`;
    $cksum =~ s{^\s+}{};
    $cksum =~ s{\s+.*$}{};
    print "$dir,$_,$cksum\n";
}

Open in new window

LVL 5
CalmSoulAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wilcoxonCommented:
What doesn't work about it?  Do you get an error?  Is the output not what you expect?  If not, how does it differ?
0
CalmSoulAuthor Commented:
This is moving very slowing ... its not multi threaded ... that the most main point
0
ozoCommented:
find /directory1 -type f | xargs cksum
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

CalmSoulAuthor Commented:
Second bug: when file name has special chars like "(" or ")" I am error invalid token
0
wilcoxonCommented:
How do you want it to multi-thread?  Split on each sub-dir under /directory1?  Start a new thread/process for each dir found?

The biggest hassle with multi-thread/process is handling output (it has a tendency to get jumbled together since each one is running asynch).
0
CalmSoulAuthor Commented:
@Wilcoxon: I haev 2.5 million files to process, all of the them are in the same dir ... I will like to start 2 threads with 100K each ... that will speed up the process.
0
CalmSoulAuthor Commented:
Here is the error on the special char:

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `sha256sum /xxx/_Ju^ftg^Procedure^(Final^7-21-04).doc'

Open in new window

0
wilcoxonCommented:
If all you want is to output the cksum, you are probably best off doing something like ozo suggests.

This will give you the syntax you want:
find /directory1 -type f | xargs cksum | perl -ne '@a = split; my ($p, $f) = $a[2] =~ m{^(.*)/([^/]+)}; print "$p,$f,$a[0]\n"'

Open in new window

0
ozoCommented:
find /directory1 -type f -print0 | xargs -0 cksum
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wilcoxonCommented:
To incorporate ozo's fix and a fix for filenames/dirs with spaces...
find /directory1 -type f -print0 | xargs -0 cksum | perl -ne '@a = split /\s+/, $_, 3; my ($p, $f) = $a[2] =~ m{^(.*)/([^/]+)}; print "$p,$f,$a[0]\n"'

Open in new window

0
CalmSoulAuthor Commented:
@wilcoxon is putting the value in next time .. not on same line
path,file_name,value
0
wilcoxonCommented:
Interesting.  Switching to null-terminated strings apparently did something odd.  Simple fix though...
find /directory1 -type f -print0 | xargs -0 cksum | perl -ne 'chomp; @a = split /\s+/, $_, 3; my ($p, $f) = $a[2] =~ m{^(.*)/([^/]+)}; print "$p,$f,$a[0]\n"'

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.