Who bloated my server? Everytime I find my server with less than 1% free space left, I'am asking this question. No one did it, so I've to find it out myself. This snippet helps a lot.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use File::Find::Rule; my %stat; $stat{getpwuid((stat($_))[4])} += (stat($_))[7] for (File::Find::Rule->file() ->name( '*' ) ->mtime( '>'.(time()-(3*24*60*60))) ->in( '.' ) ); print Dumper \%stat;

Replies are listed 'Best First'.
•Re: Who bloated my server?
by merlyn (Sage) on Jul 21, 2004 at 15:51 UTC
    use File::Finder; my %sizes; my @START = "."; $sizes{$_->[0]} += $_->[1] for File::Finder->type('f')->mtime('-3')->collect(sub { [(stat)[4, 7]] } +, @START); for (sort { $sizes{$b} <=> $sizes{$a} } keys %sizes) { printf "%20s %.2f MB\n", getpwuid($_) || "($_)", $sizes{$_}/1e6; }

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thank you, merlyn. Your File::Finder is a nice alternative to File::Find::Rule and new to me. I prefer the way you handle the mtime, in a more unix/find-like way.

      neniro

        Yeah, File::Find::Rule is especially OK if you don't really grok traditional Unix find. But I find (heh) that my years of practice with find made me always look sideways at how to do the same things with FFR, so I wrote File::Finder instead. And, you get the best of both worlds because FF can accept FFR steps too.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.