检查磁盘和系统错误的脚本
时间: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;
}
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;
}
相关阅读 更多 +
排行榜 更多 +