#!/usr/bin/perl/ - w # mon_users - monitor usr accounts # This script was created to monitor disk usage in peoples # home directories. It should work anywhere you will need to # edit all the paths. Prints out a nice little graph deal = ) $MAX_SPACE_ALLOWED = 15000000; %user_hash = {}; &get_user_info; &write_out_info ($MAX); exit(); sub get_user_info { $count = 0; open (USERS, "ls -al /houfiler_home/|") || die "Can't open ls -al +$!\n"; while (<USERS>) { #next if $count > 100; chop; $j, $j, $j, $j, $j, $month, $date, $time, $uname) = split; # If it starts with a '.', has capitals or is "" its not a username next if ($uname =~ /tim/ || $uname =~ /\./ || $uname eq "" || (lc ($un +ame) ne $uname)) ; # Make Home Directory out of username $home_dir = "/houfiler_home/$uname"; $du = `du -s -k $home_dir`; chop $du; ($disk,$junk) = split(/\t/,$du); # Store everything in a Hash Table $user_hash{"$uname"} = $disk; $count++; # print "$count\n"; } } sub sortHashByNum { $user_hash {$b} <=> $user_hash{$a}; } sub write_out_info { #header at top of each page of the report format OUTPUT_TOP = Disk Username Home Directory Space Usage (100% = 15G +) ---------------------------------------------------------------------- +--- . $~ = "OUTPUT_TOP"; write; # format for each line written to handle OUTPUT format STDOUT = @<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<@<<<<<<<<<<<<<<<< +<<<<<< $uname, $home_dir, $disk, $level . $~ = "STDOUT"; foreach $uname ( sort sortHashByNum keys %{user_hash}) { $uname =~ s/\d//g; # Make Home Directory out of username $home_dir = "/houfiler_home/$uname"; $disk = $user_hash{$uname}; $level = '*' x int (($disk*20)/$MAX_SPACE_ALLOWED+0.5); $level .= '-' x (20 - length ($level)); $level = "|".$level."|"; $disk .= "K"; # Write out formatted line to standard output write; } }

2001-03-03 Edit by Corion : Added <CODE> tags


In reply to DiskUsage.pl by JSchmitz

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!
  • 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:
    & &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.