Greetings, esteemed monks!

I kind of had the last straw yesterday with one of my users filling up our home/ partition and then conveniently going home for the evening immediately thereafter. We don't do hard quotas, but I am thinking of ways to nip these situations in the bud, as it were. One method I thought of is a CGI script that displays everyone's overall space usage in home/ so that when stuff breaks, everyone in our section knows whodunit. Other ideas include sending friendly email reminders, etc. Anyway I got kind of caught up in parsing the output of dhog (not sure if that's a standard builtin) and converting the output to "human readable" form (aka dividing by the appropriate power of 1024 and appending K,M,or G as appropriate (the partition is 20G so T isn't necessary (YET!!).

Without further ado (very raw yet):
#!/opt/local/bin/perl #script that pesters users who use up too much space in /home use strict; use warnings; use Readonly; local $\ = "\n"; #use POSIX 'strftime'; Readonly my $QUOTA => 2_000_000; #2G is reasonable, IMO (1k blo +cks) Readonly my $HOME_DIR => '/fst/home'; my @HOM_USE_BY_DIR = `sudo dhog -o $HOME_DIR`; die "Error: sudo dhog failed: $! status $? " if ($?); #print @HOM_USE_BY_DIR; my %HOM_USE_BY_DIR; foreach my $i (@HOM_USE_BY_DIR) { chomp $i; #print $i; if ( my ( $sp, $uid ) = $i =~ m{\s?(\d+)\s+/(?:\w+/)*(m\d[a-z]{3}\ +d{2})} ) { my $KMG = 0; while ( $sp > 1023 ) { #print $sp; $sp = $sp / 1024; ++$KMG; } my $mag_ind = ( $KMG == 0 ) ? 'K' : ( $KMG == 1 ) ? 'M' : ( $KMG == 2 ) ? 'G' : 'some huge multiple of 1024'; $sp = "$sp $mag_ind"; print "$uid: $sp"; } ## end if ( my ( $sp, $uid ) = $i =~ m{\s?(\d+)\s+/(?:\w+/)*(m\d +[a-z]{3}\d{2})} ) } ## end foreach my $i (@HOM_USE_BY_DIR)

As you can see I originally intended to create a hash with logonid=>space use pairs but haven't got around to that yet (any ideas welcome).

So of course I'll have to consider the overall plan and truncate all the insignificant digits, but it's a start. What experience have you guys had when begging/exhorting/recommending use of partitions other than home for users' heavy-duty data work?

I already have a cron job that runs a `df` every five minutes and sends me a warning message if any of my partitions hits 95% usage, so I was thinking of adding another one or modifying that one so that the particular user gets an email if and when their personal space usage in the home partition exceeds $QUOTA. I was also thinking of ccing our boss if the situation isn't resolved in a certain number of hours or days or if it's worsening rapidly.

BTW ChemBoy had some great ideas in the chatterbox which I hope he will post here as I am about to doze off here so pardon the quality of the code and writing.

UPDATE since ChemBoy seems to have beat me to sleep here's some of what he typed in the cb:

first
my $KiB = <>; my @pref = qw(M G T P);my $i = 0; while($i<@pref){last i +f $KiB/1024 < 1; $KiB/=1024;$i++} print "$KiB$pref[$i]iB\n"
then
perl -ne'chomp(my $KiB =$_); my @pref = qw(K M G T P);my $i = 0; while +($i<@pref){ last if $KiB/1024 < 1; $KiB/=1024;$i++} printf "${_}KiB = + %.3f$pref[$i]iB\n",$KiB'
and then
(oh dammit... too clever again. Take out the chomp and use perl -l...

UPDATE: Final form should have been (via /msg from ChemBoy)

perl -lne 'my $KiB =$_; my @pref = qw(K M G T P); my $i = 0; while($i<@pref){ last if $KiB/1024 < 1; $KiB/=1024; $i++ } printf "${_}KiB = %.3f$pref[$i]iB\n ",$KiB'

I like computer programming because it's like Legos for the mind.

In reply to Script to show space usage by users in home partition by OfficeLinebacker

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.