#!/usr/bin/perl 
#
# Mondisk; really simple script to monitor disk space.
# by Scarr, (C) 2002 Simon Carr, me@simoncarr.com
#
# Beta version that has no features.  

# Config variables
$hostname = $ENV{'HOSTNAME'}; 
$capacity = "30";
$sendmail = "/usr/sbin/sendmail -t";
$reply_to = "Reply-to: root\@ineocom.com";
$to		 = "To: scarr\@boaw.net"; 
$subject  = "Subject: $hostname: fs's more than $capacity%,"; 

@df = `/bin/df -h` or die "can't find df?"; 

foreach $df_line (@df) { 
	$df_line =~ s/\ +/\ /g;
	# Filesystem Size Used Avail Capacity Mounted on	
	( $a,        $b,  $c,  $d,   $e,      $f) = split(" ",$df_line);

	$e =~ s/\%//g; 

	if($e >= $capacity && $a =~ /^\//) { 
		$out .= "$a mounted at $f is at $e% with $d free!\n"; 
		$subject .= " $f"
	}

}

if($out) { 
	open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
	print SENDMAIL $to."\n";
	print SENDMAIL $reply_to."\n";
	print SENDMAIL $subject."\n";
	print SENDMAIL "Content-type: text/plain\n\n";
	print SENDMAIL $out."\n";
	close(SENDMAIL);
}
