Using Perl for this would certainly be better/easier than using a shell script. You have the choice of using perl modules (as suggested in the earlier reply) or using back-tick runs of handy shell utilities to collect information and take appropriate actions (I often do both).

If you're working on a diverse network (i.e. running on different hosts that might have different flavors of unix, or at least different versions of the "standard" df utility), then you really want to use Filesys::DiskFree, so you won't need to worry about figuring out how to parse different formats of df output. (And then there's "Mail::Send" to make the mailing part easier too.)

I've never been a whiz at shell scripts, but they tend to look awfully clumsy and difficult when it comes to doing anything really computational. Here's an example of a script to do what you specified (tested on linux and solaris):

use strict; use Mail::Send; use Filesys::DiskFree; # This will check all mounted volumes, both local and NFS, # and send separate email reports listing the ones over # 90% full and the ones over 70% full. my $fs = new Filesys::DiskFree; $fs->df(); my @vols = sort $fs->disks(); my ( $yellowFlag, $redFlag ); for my $vol ( @vols ) { my $dev = $fs->device( $vol ); next unless ( $fs->total( $dev ); # some solaris vols may be 0 my $pct_used = $fs->used( $dev ) / $fs->total( $dev ); $yellowFlag .= "$vol ($dev) is over 70% full\n" if ( $pct_used > 0.7 ); $redFlag .= "$vol ($dev) is over 90% full\n" if ( $pct_used > 0.9 ); } if ( $yellowFlag or $redFlag ) { my $msg = new Mail::Send; if ( $yellowFlag ) { $msg->to( 'bureaucrat@my.org' ); $msg->subject( 'Time to buy more disk!' ); my $fh = $msg->open; print $fh $yellowFlag; $fh->close; } if ( $redFlag ) { $msg->to( 'sysadmin@my.org' ); $msg->subject( 'Time to rattle some cages!' ); my $fh = $msg->open; print $fh $redFlag; $fh->close; } }
update: fixed the logic for appending lines to the two different reports.

In reply to Re: Checking filesystems? by graff
in thread Checking filesystems? by incarnadine

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.