For what it's worth, I took a look at your code and I've tried to give you a few helpful hints on another way to do it. I've placed my comments inline.

#!/usr/bin/perl # # Sorry for the simplicity of this script, but as a first submission.. +. # # Emails/Pages me when a filesystem > 90% full # # always use strict use strict; # make a variable to easily change some behavior my($warn_percentage) = 90; # predeclare our variables (not necessary, but probably a good idea) my(%df); # df hash that holds all our information my($host); # hostname # Rather than 3 backticks for df, just do it once and parse it with pe +rl! # Also, make $fs into an array instead of string then split to array # Finally, we don't really need $full, since that's just grep /100/,@f +s #$df=`df -lk 2>/dev/null`; #$fs=`df -lk 2>/dev/null | grep -v used | cut -d'%' -f2 | grep -v deni +ed`; #$full=`df -lk 2>/dev/null | grep -v used | cut -d'%' -f1`; foreach (`df -lk 2>/dev/null`) { if (/(\b\d+)%\s+(\S+)$/) { $df{$2} = $1; } } # removed some string manipulation that isn't needed any longer #$full =~ s/.*(..\d)$/\1/mg; #$fs=~s/\s+/ /g; #$full=~s/\s+/ /g; #@fs=split(" ",$fs); #@full=split(" ",$full); # We can combine this into one statement #$host=`hostname`; #chomp($host); chomp($host = `hostname`); # this loop changes somewhat #$fs=@fs; #chomp($date); # where is $date coming from? # note that the mailx stuff isn't tested, as I don't have mailx on my +system foreach (keys %df) { if ($df{$_} > $warn_percentage) { print "Host: $host Filesystem: $_ is $df{$_}% full!\n"; system("mailx -s \"$host:$_ is $df{$_}%\" youremail\@host.com << / +dev/null"); } } #while ($fs) { # $fs=shift(@fs); # $full=shift(@full); # chomp($fs); # chomp($full); # if ($full > 90) { # print "Host: $host Filesystem: $fs is ${full}% full!\n"; # @chk=grep(/$fs:$full/,@log); # not sure what all this log stuff i +s... # undef(@log); # $chk=@chk; # close(LOG); # } # if ($chk == 0) { # `mailx -s "$host:$fs is ${full}%" youremail\@host.com <<EOF #$df #EOF #`; # `mailx -s "$host:$fs is ${full}%" mypager\@pagerhost.com <<EOF #EOF #`; # } #}
Hope that helps!

In reply to RE: Full Filesystem Notification by Shendal
in thread Full Filesystem Notification by prodevel

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.