#!/usr/bin/perl ############################################################ # # Config Section # The @server_list array is just that - duh. # The "Local" value is a keyword and refers to the local machine. @server_list = ("Local", "host1.server.com", "host2.server.com.com", " +host3.server.com", "host4.server.com"); # This is the warning level (in percent). When a filesystem passes # this percentage in used space, a warning report is generated $warning_threshold = 80; ############################################################ if ($ARGV[0] eq "-?" || $ARGV[0] eq "--help") { print "Usage: diskfree [-w] [-? | --help]\n"; print "\t-w\t\t Display warnings only\n"; print "\t-? | --help\t Usage screen\n"; exit 1; } $warnings = ""; $detail_report = ""; foreach $server (@server_list) { $detail_report = $detail_report . "$server Disk Usage\n"; $detail_report = $detail_report . "--------------------------- +---------------\n"; $detail_report = $detail_report . "Use% | Mount | Size | Ava +il\n"; $detail_report = $detail_report . "--------------------------- +---------------\n"; if ($server eq "Local") { @diskusage = `df -hP`; } else { @diskusage = `ssh "$server" "df -hP"`; } for ($i = 1; $i <= $#diskusage; $i++) { @usage_detail = split (/\s+/,$diskusage[$i]); $usage_detail[4] =~ s/%//g; if ($usage_detail[4] > $warning_threshold) { $warnings = $warnings . "*WARNING* $server: $u +sage_detail[5] ($usage_detail[0]) is at $usage_detail[4]%\n"; $detail_report = $detail_report . "$usage_deta +il[4]% \t $usage_detail[5] \t $usage_detail[1] \t $usage_detail[3]" . + "\n"; } else { $detail_report = $detail_report . "$usage_deta +il[4]% \t $usage_detail[5] \t $usage_detail[1] \t $usage_detail[3]" . + "\n"; } } $detail_report = $detail_report . "--------------------------- +---------------\n\n"; } if ($ARGV[0] eq "-w") { if ($warnings eq "") { print "No warnings.\n"; } else { print "$warnings\n"; } } else { print "$warnings\n"; print "$detail_report\n"; }

In reply to diskfree by vxp

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.