[SQLView]SSQL00_NEmployee_Email_v

第一支手工打造的Perl

AC posted @ Wed, 19 Mar 2008 17:35:44 +0800 in Job with tags Perl Coding , 1072 readers

為了偵測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" }
}

Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter