文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>检查磁盘和系统错误的脚本

检查磁盘和系统错误的脚本

时间:2007-08-10  来源:evegl

#!/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;
}
相关阅读 更多 +
排行榜 更多 +
宝宝情商养成宝宝巴士

宝宝情商养成宝宝巴士

休闲益智 下载
燥热手机版

燥热手机版

飞行射击 下载
巨人狙击手安卓版

巨人狙击手安卓版

飞行射击 下载