#!/usr/bin/perl use warnings; use strict; my %cmd_data = ( generic=> { regex=> '\s*(\d+)\s+\d+\s+\S+\s+\d+\s+\S+\s+\S+\s+(\d+)\s+\w+\s+\d+\s+\S+\s+(.+)[\n\r]+', order=> '$inode=$1;$key=$2;$val=$3;', }, ); my $cmd = 'generic'; my %HoA = &gen_hoa(%{$cmd_data{$cmd}}); my %stats = &list_hoa(%HoA); print "=====================================================================\n"; print "Duplicates: $stats{'duplicates'}\n"; print "Orphans: $stats{'orphans'}\n"; print "Total files: $stats{'total'}\n"; print "Bytes checked: $stats{'bytes'} ("; printf "%1d", ($stats{'bytes'}/1024/1024); print "MB)\n"; ######################################################### # SUBROUTINES ######################################################### sub gen_hoa { my %cmd_data = @_; my (%HoA, $line, $val, $key, $inode); while (defined($line = )) { $line =~ /$cmd_data{'regex'}/s; eval($cmd_data{'order'}); push @{$HoA{$key}}, $val; } return %HoA; } sub list_hoa { my %HoA = @_; my ($j, $key); my $dups = 0; my $orphans = 0; my $bytes = 0; foreach $key ( keys %HoA ) { $bytes = ($bytes+($key * ( $#{$HoA{$key}} +1 ))); if ($#{$HoA{$key}} > 0) { print "$key:\n"; foreach $j (@{$HoA{$key}}) { print " $j\n"; } $dups = $dups + $#{$HoA{$key}} + 1; } elsif ($#{$HoA{$key}} == 0){ delete($HoA{$key}); ++$orphans; } } my %stats = ( "duplicates", $dups, "orphans", $orphans, "total", ($dups+$orphans), "bytes", $bytes, ); return %stats; } sub timestr { # returns local time string in a format like: 200707051251 my @date = localtime(); my $year = $date[5] + 1900; my $month = sprintf("%02d", $date[4] + 1); my $day = sprintf("%02d", $date[3]); my $hour = sprintf("%02d", $date[2]); my $minute = sprintf("%02d", $date[1]); my $second = sprintf("%02d", $date[0]); return "$year$month$day$hour$minute$second"; }