我有一個perl腳本,它以HTML格式從Oracle數據庫打印表格內容。如何在perl中有條件地發送電子郵件警報
我的腳本會每天的基礎上,這將不僅僅是電子郵件的簡單的SQL查詢的O/P上運行(選擇查詢)
現在我想我的腳本停止電子郵件警報每當表中的記錄數是NULL即表中沒有記錄。
這裏是我的部分腳本
$retCode = executeSQL("select firstname,lastname,employee_id from employee");
if ($retCode) {
push(@HTML, "<tr><td> </td><td></td><td>");
push(@HTML, "<td></td><td></td></tr>\12");
}
push(@HTML, "</table>\12\12");
push(@HTML, "COUNT : $count\12");
&sendMail;
sub sendMail {
$sub = "sample data";
$from = '[email protected]';
$to = '[email protected]';
open(MAIL, "|/usr/lib/sendmail -t");
print MAIL "From: $from \12"; print MAIL "To: $to \12";print MAIL "Cc: $Cc \12";
print MAIL "Subject: $sub \12";
print MAIL "Content-Type: text/html \12";
print MAIL "Content-Disposition:inline \12";
print MAIL @HTML;
close(MAIL);
}
sub executeSQL {
my $SQL = $_[0];
chomp($SQL);
print "$SQL\12";
my $hostname = $ENV{"ORACLE_DB"};
my $dbh = CommonFunctions::connect_DBI($hostname, "USERNAME", "PASSWORD")|| die "ERROR : Unable to connect to $hostname: $DBI::errstr\n\n";
my $sth = $dbh->prepare($SQL);
$sth->execute or die "EXEC ERROR $sth->errstr";
$count = 0;
while (@ary = $sth->fetchrow_array) {
$count++;
push(@HTML, "<tr>");
foreach(@ary) {
chomp($_);
push(@HTML, "<td>$_</td>");
print "$_,";
}
push(@HTML, "</tr>\12");
}
}
...你的問題是什麼? – Sobrique
當sql查詢沒有產生任何行時,我不應該觸發電子郵件。 – stephenjacob
這是一個陳述,而不是一個問題。 :) – simbabque