博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

系统※网络技术实验室

System & Databses & Networking & Security & Services
evegl.cublog.cn
检查磁盘和系统错误的脚本
#!/usr/bin/perl
use strict;
use Net::SMTP;
use Time::Local;
my $smtp_server = '@yoursmtpserver@';
my $from_mail = '@youremailaddress@';
my $to_mail = '@sendtoemailaddress@';
my ($hostname) = (`/sbin/ip addr show dev eth0 | awk '/inet[^6]/{print \$2}' | cut -d/ -f1` =~ m/(\d+\.\d+\.\d+\.\d+).*/);
my $dmesg = `dmesg`;
my $time = (scalar (localtime));
my $smtp;
# Set threshold Values for sendmail
my $full = 90;
my $warn = 95;
my @array=();
#print $hostname,"\n";
open(DF,"df -h -P $ARGV[0] -T | grep ext |");
foreach (<DF>) {
        chomp($_);
        if ($_ =~ /($ARGV[0]).*\s+(\d+)\%.*$/) {
                if ($2 > $full) {
                        push(@array,$_);
                }
        }
}
# Used Net::SMTP modules
if (scalar(@array) > 0) {
        #my $smtp = Net::SMTP->new(${smtp_server});
        $smtp = Net::SMTP->new(${smtp_server}, Timeout => 60);
        $smtp->mail(${from_mail});
        $smtp->to(${to_mail});
        $smtp->data();
        $smtp->datasend("To:${to_mail}\n");
        $smtp->datasend("From:${from_mail}\n");
        $smtp->datasend("Subject:Disk almost full on $hostname ($time)\n");
        $smtp->datasend("\n");
        foreach (@array) {
                $smtp->datasend("$_\n");
        }
        $smtp->datasend();
        $smtp->quit;
}
if ($dmesg =~ /error/i) {
        $smtp = Net::SMTP->new(${smtp_server}, Timeout => 60);
        $smtp->mail(${from_mail});
        $smtp->to(${to_mail});
        $smtp->data();
        $smtp->datasend("To:${to_mail}\n");
        $smtp->datasend("From:${from_mail}\n");
        $smtp->datasend("Subject:Hardware error on $hostname ($time)!!!\n");
        $smtp->datasend("\n");
        $smtp->datasend("$hostname needs to be checked right now!\n");
        $smtp->datasend();
        $smtp->quit;
}

发表于: 2007-08-10,修改于: 2007-08-10 09:53,已浏览399次,有评论0条 推荐 投诉

给我留言
版权所有 ChinaUnix.net 页面生成时间:0.0085