[LON-CAPA-cvs] cvs: modules /matthew/disk_usage tally.pl tally_output.txt

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 03 Nov 2004 21:17:44 -0000


This is a MIME encoded message

--matthew1099516664
Content-Type: text/plain

matthew		Wed Nov  3 16:17:44 2004 EDT

  Added files:                 
    /modules/matthew/disk_usage	tally.pl tally_output.txt 
  Log:
  Script to report disk usage and output for S10.
  
  
--matthew1099516664
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20041103161744.txt"


Index: modules/matthew/disk_usage/tally.pl
+++ modules/matthew/disk_usage/tally.pl
#!/usr/bin/perl -w
#
use strict;

my @file_patterns = ('^activity.log$',
                     '_spreadsheets.db$',
                     '^chatroom.log$',
                     '_spreadsheets.hist$',
                     '\.hist$',
                     '^default_.*db',
                     '^default_.*hist',
                     '^environment.db',
                     '^discussiontimes.db',
                     '^discussiontimes.hist',
                     '^environment.db',
                     '^environment.hist',
                     '^email_status.db',
                     '^email_status.hist',
                     '^msu_.*db',
                     '^msu_.*hist',
                     '^nohist_calculated*db',
                     '^resourcedata.db',
                     '^scantron_',
                     '^classlist.db',
                     '^nohist*',
                     '^calendar.db*',
                     '.',
                     );

# The results of ls -lR  /home/httpd/lonUsers/msu > /tmp/s10_files.txt
my $inputfile = 's10_files.txt';
#my $inputfile = 'testfiles.txt';
my $lines = 627969;

open(IN,$inputfile) || die "Unable to open $inputfile\n";
my %sum;
my %class_sum;
my %class_hist;
my %class_count;
my $count;
while(<IN>) {
    if (++$count % 10000 == 0) {
        print $count.' / '.$lines.$/;
    }
    #if ($count == 10000) { last;}
    chomp;
    next if ($_ =~/^\s*$/);
    if ($_ =~m|^/|) {
        # in a directory
        # print $_.$/;
        next;
    }
    if ($_=~/^d/ || $_=~/^total \d+$/) {
        # skip directories and 'total ' lines.
        next;
    }
    my $processed = $_;
    $processed =~ s/\s+/ /g;
    my ($size,$filename) = (split(' ',$processed))[4,8];
    my $match;
    foreach my $pattern (@file_patterns) {
        if ($filename =~ /$pattern/) {
            $sum{$pattern} += $size;
            $match++;
        }
    }
    #
    if ($filename =~ /^msu_(.*).db$/) {
        $class_sum{$1}+= $size;
        $class_count{$1}++;
    } elsif ($filename =~ /^msu_(.*).hist$/) {
        $class_hist{$1}+=$size;
    }
    #
    if (! $match) {
        print "no matches for ".$processed.$/;
    }
}

close IN;
my ($pattern,$value,$value2,$value3);

print $/."    pattern                                 size".$/;
print "------------------------------------------------".$/;
foreach $pattern (@file_patterns) {
    if (! exists($sum{$pattern})) {
        $sum{$pattern}=0;
    }
    $value = &comma_number($sum{$pattern});
    $value2 = '';
    $value3 = '';
    write STDOUT;
}

print $/.
    "    class                                    dbs              hist   count".$/.
    "--------------------------------------------------------------------------".$/;
foreach $pattern (sort (keys(%class_sum))) {
    $value = &comma_number($class_sum{$pattern});
    $value2 = &comma_number($class_hist{$pattern});
    $value3 = $class_count{$pattern};
    write STDOUT;
}

format STDOUT =
    @<<<<<<<<<<<<<<<<<<<<<  @>>>>>>>>>>>>>>>>>>> @>>>>>>>>>>>>>>>>  @>>>>>
$pattern, $value, $value2,$value3