neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; # This script will the top ten space users # of any directory # Neil Watson Mon Mar 1 13:05:11 EST 2004 use Getopt::Std; use File::Find; use Data::Dumper; my (%opt, $utotal, $uid, $uname, $fname, %size, $size, %files); my ($count); # options available # -d <dir to check> getopts("d:", \%opt); my $dir = $opt{d}; # get file file information find(\&wanted, $dir); # get top ten offenders print "User\t\tTotal (kb)\n"; foreach $uname (sort keys %size){ print $uname."\t\t".$size{$uname}."\n"; } #print Dumper(%files); sub wanted{ # scan only regular files if (-f){ # owner of file but skip # if owner is not a user # (uid < 500) $uid = (lstat($_))[4]; unless ($uid < 500){ $uname = getpwuid $uid; # gather name of file $fname = $File::Find::name; # size of file (kb) $size = (lstat($_))[7]; $size = int($size/1000); # store in a hoh # username {filename} => filesize $files{$uname} {$fname} = $size; # keep running total of each # user's files $size{$uname} += $size; } } }
Now that I look at my hoh data structure I'm not sure that is it ideal. For instance, how would I select the top ten space users? I think there must be a more efficient way to do this so I'm throwing this out to my fellow monks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Monitoring disk usage
by Tomte (Priest) on Mar 05, 2004 at 16:12 UTC | |
by neilwatson (Priest) on Mar 05, 2004 at 16:19 UTC | |
by tachyon (Chancellor) on Mar 05, 2004 at 17:01 UTC | |
by Tomte (Priest) on Mar 05, 2004 at 17:21 UTC | |
by tachyon (Chancellor) on Mar 05, 2004 at 22:33 UTC | |
by ambrus (Abbot) on Mar 05, 2004 at 18:03 UTC | |
|
Re: Monitoring disk usage
by TomDLux (Vicar) on Mar 05, 2004 at 16:29 UTC | |
by neilwatson (Priest) on Mar 05, 2004 at 16:46 UTC | |
by thewalledcity (Friar) on Mar 05, 2004 at 19:36 UTC |