perl ping檢測(cè)功能腳本代碼
我的第一個(gè)用于生產(chǎn)環(huán)境的perl腳本,雖然不是很優(yōu)秀,但也邁出了扎實(shí)的一步 :)
領(lǐng)導(dǎo)有任務(wù),給一批IP列表,ping每一臺(tái)機(jī)器,如果沒(méi)有響應(yīng)就發(fā)郵件通知,通知的郵件需要分開(kāi),不能通知一個(gè)列表,得一封一封的通知.
用到email::send模塊,因?yàn)樾枰玫紾mail
#!/usr/bin/perl
use warnings;
use strict;
use Email::Send;
use Email::Send::Gmail;
use Email::Simple::Creator;
my @list = qw/
1.1.1.1
2.2.2.2
3.3.3.3
/;
foreach my $re (@list){
my $p = `ping $re -c 3`;
if($p=~/100% packet loss/){
my $email = Email::Simple->create(
header => [
From => 'monitor@a.com',
To => 'monitor@b.com',
Subject => "$re 100% packet loss",
],
body => "$re the server is down!\n",
);
my $sender = Email::Send->new(
{ mailer => 'Gmail',
mailer_args => [
username => 'monitor@a.com',
password => 'xxx',
]
}
);
eval { $sender->send($email) };
die "Error sending email: $@" if $@;
}
}
相關(guān)文章
Perl使用Tesseract-OCR實(shí)現(xiàn)驗(yàn)證碼識(shí)別教程
這篇文章主要介紹了Perl使用Tesseract-OCR實(shí)現(xiàn)驗(yàn)證碼識(shí)別教程,Tesseract-OCR是一個(gè)開(kāi)源圖形識(shí)別引擎,需要的朋友可以參考下2014-06-06Perl中的10個(gè)操作日期和時(shí)間的CPAN模塊介紹
這篇文章主要介紹了Perl中的10個(gè)操作日期和時(shí)間的CPAN模塊介紹,本文介紹了Date::Manip、DateTime、Time::Format、Time::Interval、Date::Convert、Benchmark、Time::Normalize、Regexp::Common::time等10個(gè)模塊,需要的朋友可以參考下2015-02-02perl高級(jí)排序,<=>操作符,飛船操作符
perl高級(jí)排序的關(guān)鍵在于要指定排序的方式,使用的操作符是spaceship operator(<=>)2013-02-02perl 指定長(zhǎng)度并生成一個(gè)隨機(jī)的DNA序列的腳本代碼
perl 指定長(zhǎng)度并生成一個(gè)隨機(jī)的DNA序列的代碼,有需要的朋友可以參考下2013-03-03perl數(shù)組的多數(shù)字下標(biāo)示例代碼
perl數(shù)組中正常的下標(biāo)運(yùn)算,想必大家都比較熟悉,這里不作說(shuō)明。本文想說(shuō)的是perl數(shù)組下標(biāo)的多數(shù)字取值,可以極大的方便數(shù)組的操作2013-02-02