i am writing a script that does a number os usage and space checking routines. having trouble with one of them.
the plan here is to recurse thru a directory, record each uniqe user and add the size of the directories per user and then spit out a total like this:
User Total usage in /some/dir
foo 450MB
bar 550MB
here is some code:
use File::Find;
find (\&wanted_user, "$dir");
sub wanted_user
{
%sum = ();
next unless (-d $_);
($user,$size) = (stat($_))[4,7] or die "can't stat: $!\n";
push ( @{$sum{$user}}, $size );
}
foreach $user (sort keys %sum) {
print "$user: @{$sum{$user}}\n";
}
----------------
questions:
1. it prints nothing. it should at least print something like 11847: 44645, 45466....
2. after question 1 is solved, what is the best way to add the size into a total.
something like: push ( @{$sum{$user}}, ++$size ); ?
3. also I may have to get rid of the stat() way of getting the user and size because there are some dirs that have dirs and files that i do not have access too and will generate erros instead of stating. i know i can parse a
`ls -ld` but is there a better way?
Thanks for any help
Jim
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.