Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

#/usr/bin/perl -w use File::Find; use strict; # Written by David Wakeman. # dwakeman@umagroup.com # # This program is free # software; you can redistribute it and/or modify it # under the same terms as Perl itself. Use under # GNU General Public License or Larry Wall's "Artistic # License". # Change this option to suit your needs. Make sure # you escape all backslashes with a backslash. eg: # f:\\folder\\another folder\\here my $dir = "m:\\"; # Change this to use whatever filename you desire. my $file = "usage-report.txt"; # Don't change anything below here unless you know # what you are doing. my @dirlist = <$dir*>; my $sum = 0; my $mbSum = 0; my $gbSum = 0; my $totalLargeSum = 0; my $totalSmallSum = 0; my $totalSum; my %smallUsage = (); my %largeUsage = (); my %noUsage = (); #------------------------------------------- # the meat of the program - calls all # our subs. open(FILE, "+>$file") || die "Can't open file: ($!)\n"; findUsage(); getTotals(); close(FILE); #------------------------------------------- # and below are all our subroutines sub findUsage { foreach my $directory (@dirlist) { print "Checking $directory..."; find sub { $sum += -s }, $directory; # Find goes th +rough all sub dirs $totalSum += $sum; # Used for later $directory =~ /m:\\(\w+)/; # take out the m:/ i +n the dir name my $key = $1; # if ($sum > 1000000000) # Check if > 1 GB { $gbSum = $sum / 1073741824; # Convert $sum into + GB from b $gbSum =~ /(\d+)\.(\d\d\d)/; $largeUsage{$key} = "$1" . "." . "$2"; } elsif ($sum > 1) { # Check if > 1 b $mbSum = $sum / 1048576; # Convert $sum into MB + from b $mbSum =~ /(\d+)\.(\d\d)/; $smallUsage{$key} = "$1" . "." . "$2"; } else { # user share is blank $noUsage{$key} = "0"; } print "completed\n"; $sum = 0; # Clear sum for next dir } $totalSum = $totalSum / 1073741824; # Convert to GB $totalSum =~ /(\d+)\.(\d\d\d)/; $totalSum = "$1" . "." . "$2"; } sub getTotals { print FILE "===========================\n\n"; print FILE "Total Usage:\t $totalSum GB\n"; foreach my $user (sort keys %largeUsage) # get our tota +l %largeUsage { $totalLargeSum += $largeUsage{$user}; } print FILE "Large usage:\t $totalLargeSum GB\n"; foreach my $user (sort keys %smallUsage) # get our tota +l %smallUsage { $totalSmallSum += $smallUsage{$user}; } $totalSmallSum = $totalSmallSum / 1024; # Switching + our total into $totalSmallSum =~ /(\d+)\.(\d\d\d)/; # GB from MB. $totalSmallSum = "$1" . "." . "$2"; print FILE "Small usage:\t $totalSmallSum GB\n\n"; print FILE "===========================\n\n"; largeUsage(); smallUsage(); noUsage(); } sub largeUsage { print FILE "Users with > 1GB of usage:\n"; print FILE "\#--------------------------------\n\n"; foreach my $user (sort keys %largeUsage) # print out ou +r %largeUsage { # hash. print FILE "USER :\t $user\n"; print FILE "USAGE :\t $largeUsage{$user}" . " GB" . "\n\n"; } } sub smallUsage { print FILE "\nUsers with < 1GB of usage:\n"; print FILE "\#--------------------------------\n\n"; foreach my $user (sort keys %smallUsage) # Print out ou +r %smallUsage { # hash. print FILE "USER :\t $user\n"; print FILE "USAGE :\t $smallUsage{$user}" . " MB" . "\n\n"; } } sub noUsage { print FILE "\nUsers with no usage on $dir\n"; print FILE "\#--------------------------------\n\n"; foreach my $user (sort keys %noUsage) # print out o +ur %noUsage { # hash. print FILE "USER :\t $user\n"; } }

In reply to User drive usage reporter by djw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (11)
    As of 2015-07-08 04:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (94 votes), past polls