http://qs321.pair.com?node_id=96058


in reply to faster filesystem stats

I do a file::find here and run a secondary script that reads the logs and stats each file for the file size here:

use strict; my ($type, $server,$out,$in,@input,$total,$kbytes,$mbytes); my @servers=('Server'); my $dir1='//machine/share'; my @types=('swf','asf','avi','mp2','mp3','mpg','mpga','mpe','mpeg','wa +v','mov','qt','mid','midi','ra','ram','rmi','rmj','rmx','zip','exe',' +wm','wma'); foreach $type (@types){ $total=0; my $out="$dir1/sifted/$type\.txt"; my $out2="$dir1/sifted/$type-ok\.txt"; open OUT, ">$out" or die "Cannot open $out for write :$!"; foreach $server (@servers){ $in="$dir1/$server\.txt"; open IN,"$in" or next; @input=<IN>; chomp @input; foreach (@input){ if (/\.$type$/i){ $kbytes = (stat)[7]/1024; $total+=$kbytes; print OUT "$_\t$kbytes KB\n"; } } close IN; } $mbytes=$total/1024; print OUT "\n\nTotal: $mbytes MB\n"; close OUT; if ($mbytes eq 0){ rename $out, $out2; } print "Finished $type...\n"; }

The main script takes 8 hours for for 40 servers with gigs and gigs per server. The second script takes 15 minutes to run through. Defining the types of files actually speeds up the process as the stat is the part that really slows the code down ($kbytes = (stat)[7]/1024; That's the file size portion.) You could combine these into something you can use...

-OzzyOsbourne