Listing 4. Perl Script to Check Disk Usage

#!/usr/bin/perl
# 1999: Salmar Consulting Inc. www.salmar.com
# checkdfusage.pl : checks disk usage in
# percentage and alerts sys admin if greater
# than 90%
&check_dfusage;
exit();
# Subroutines #
sub check_dfusage {
  @message='df';
  $message_text = '';
  foreach (@message) {
    ($dirname, $arg1, $arg2, $arg3, $arg4, $arg5,
        $arg6) = split (' ', $_, 7);
    ($arg4num,$therest) = split('%',$arg4,2);
    if ($arg4num > "90") {
      $message_text .= "Directory $dirname is now " .
      " at $arg4num\n";
      }
#print $arg4 . "\n";
  }
  if ($message_text ne '') {
    $smbclient = "/usr/bin/smbclient -U root";
    $smbhost = 'speedy';
    &sendmessage;
  }
}
sub sendmessage {
  open(SF,"|$smbclient -M $smbhost");
  print SF "$message_text";
  close(SF);
}