#!/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.
In reply to Monitoring disk usage by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |