奉献一篇磁盘检测报警脚本

#!/usr/bin/perl
use strict;
use Net::SMTP;
my $max=0.8;
my @msg;
open(FH,"df -P|");
foreach my $data (<FH>){
   if(($data=~/^\//)and!($data=~/\/mnt/)){
         my(@arr)=split " ",$data;
         if($arr[2]/$arr[1]>$max){
              push(@msg,"$arr[5] $arr[4]" ); 
           }
    }
}
if(defined(@msg)){
   foreach my $cont (@msg){
       my $mailhost='127.0.0.1';
        my [email protected]'">$mailfrom=' [email protected]';
        my [email protected]'">$mailto=' [email protected]';
        my $subject="Disk Warn";
        my $smtp = Net::SMTP->new($mailhost,Hello =>"localhost",Timeout => 30,Debug => 0,);
                $smtp->mail($mailfrom);
                $smtp->to($mailto);
                $smtp->data();
                $smtp->datasend("To: $mailto\n");
                $smtp->datasend("From: $mailfrom\n");
                $smtp->datasend("Subject: $subject\n");
                $smtp->datasend("\n");
                $smtp->datasend("磁盘警告:$cont\n");
                $smtp->dataend();
        $smtp->quit;
      }
}

你可能感兴趣的:(脚本,职场,perl,休闲)