Hi, >>"Kai" == Kai Henningsen <[EMAIL PROTECTED]> writes:
Kai> I just tried to write a quich checker in Perl, and discovered Kai> that the data is indeed in a suboptimal format. My point. Kai> Easy, huh? Except for one problem. The typical du output has the Kai> outer directories include the space already mentioned for the Kai> inner ones. Kai> So I need to subtract those. Kai> Now, while that's easy for a human, I'd expect it to at least Kai> double the size of this script. Much better if the size came Kai> pre-subtracted. Kai> Fortunately, that's easy to do. Use du -S instead of plain du. Makes sense. Kai> Ok, Manoj. Now we have both a tool and a file format for that Kai> tool. Now what? I don't now why you singled me out, but now that you have, I think this should be made into a policy proposal, and should be included into the next policy weekly thing that christian periodically sends our way. I have taken your script, removed all global variables, check the open and close of the pipe to df, used longer variable names, user friendlier error messages, and couched it to be a perl library, and yet still run as script if called directly. (I really like this trick). That way, this mechanism can see the light of day and get discussed. Maybe one can time this script on some of the large packages being discussed? I think once this is policy, dpkg-ftp; dpkg-mountable, dftp and friends can possibly include this; or else it could get into dpkg-perl. I'm glad that this discussion at least got someone to implement this feature ;-) manoj -- "A stitch in time would have confused Einstein." Anonymous Manoj Srivastava <[EMAIL PROTECTED]> <http://www.datasync.com/%7Esrivasta/> Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E ______________________________________________________________________ #! /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;