第一支手工打造的Perl
為了偵測RSA Application是否有執行錯誤
所以利用Perl寫了一隻程式
#!/usr/local/bin/perl
use Mail::Sendmail;
$file_name = "ldapsync.log";
open (querylog,"$file_name") || die "Can't read file $file_name : $!\n";
while (<querylog>)
{
if (/Error occurred connecting to LDAP server/){
Smail();}
else{
}
}
print ("Detect complete");
close(querylog);
sub Smail(){
%mail = (
To => 'Jeffrey Chien <jeffrey.chien@mailbox.com>',
From => 'RSAQuery@mailbox.com',
Cc => 'Jacky Wang <jackywang@mailbox.com>, Chester Lin <chesterlin@mailbox.com>',
Subject => 'RSQ Query AD fail!',
#'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);
$mail{Smtp} = 'mail.server.ip.address';
#$mail{'X-custom'} = 'My custom additionnal header';
$mail{'mESSaGE : '} = "The RSA Application Service is down! Please check it on RSA Server";
# cheat on the date:
$mail{Date} = Mail::Sendmail::time_to_date( time() - 86400 );
if (sendmail %mail)
{ print "Mail sent OK.\n" }
else
{ print "Error sending mail: $Mail::Sendmail::error \n" }
}
use Mail::Sendmail;
$file_name = "ldapsync.log";
open (querylog,"$file_name") || die "Can't read file $file_name : $!\n";
while (<querylog>)
{
if (/Error occurred connecting to LDAP server/){
Smail();}
else{
}
}
print ("Detect complete");
close(querylog);
sub Smail(){
%mail = (
To => 'Jeffrey Chien <jeffrey.chien@mailbox.com>',
From => 'RSAQuery@mailbox.com',
Cc => 'Jacky Wang <jackywang@mailbox.com>, Chester Lin <chesterlin@mailbox.com>',
Subject => 'RSQ Query AD fail!',
#'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);
$mail{Smtp} = 'mail.server.ip.address';
#$mail{'X-custom'} = 'My custom additionnal header';
$mail{'mESSaGE : '} = "The RSA Application Service is down! Please check it on RSA Server";
# cheat on the date:
$mail{Date} = Mail::Sendmail::time_to_date( time() - 86400 );
if (sendmail %mail)
{ print "Mail sent OK.\n" }
else
{ print "Error sending mail: $Mail::Sendmail::error \n" }
}