[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: making room



Hi,

	I thought I posted this here, but ...

	Getting the information on the fly has scalability and
 response time problems (tried xbooks or picons-usenix lately?)

	The files included by some herlper packages put in data which
 is not quite suited for the size tool; (not surprising since the data
 format was decided before designing the program). We have discovered
 that a du -S data form is better suited to our needs, and have come
 up with the following script that can use the du -S data (as opposed
 to the old du -s data).

	Ths has yet to be debated and made policy.

	manoj

______________________________________________________________________
#! /usr/bin/perl -w

package Check_DU;

use strict;
use diagnostics;
use Carp;
require 5.001;

sub check_du {
  my %data;
  
  # find out the mount points of the devices
  open DF, "df |" or die "Could not run df:$!" ;
  while (<DF>) {
    m!/dev.*\s(/\S*)! or next;
    my $device_no = (stat($1))[0];
    $data{$device_no}{'Name'} = $1;
  }
  close DF or die "Could not close pipe from df:$!" ;
  
  # read all the du -S files given on the command line
  while (<>) {
    my ($size, $dir_name) = split /\s+/, $_;
    my $device_no = (stat("/$dir_name"))[0];
    $data{$device_no}{'Size'} += $size;
  }
  return \%data;
}

sub print_du {
  my %params = @_;
  croak("Need argument 'Size Data'") unless defined $params{'Size Data'};
  
  
  for (sort keys %{$params{'Size Data'}}) {
    next unless $params{'Size Data'}{$_}{'Size'};
    printf "%10d %s\n", $params{'Size Data'}{$_}{'Size'}, 
                        $params{'Size Data'}{$_}{'Name'};
  }
}

sub test_du {
  my $data = &check_du();
  &print_du('Size Data' => $data);
}

{ # Execute simple test if run as a script
  package main; no strict;
  eval join('',<main::DATA>) || die "$@ $main::DATA" unless caller();
}


1;

__END__

# Test the library
&Check_DU::test_du();

1;

-- 
 "The part I think I'd like best is crushing people who get in my
 way." Calvin
Manoj Srivastava  <srivasta@acm.org> <http://www.datasync.com/%7Esrivasta/>
Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05  CC 2D 27 12 1D F5 E8 6E


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: