不懂perl,亂改一氣:(,紅色部分為添加的內容
#!/usr/bin/perl -w
$ENV = 'en_US'; # Hack to fix RH bug #81144
use strict;
use Net::SMTP;
##########################################################################
# $Id: logwatch.pl,v 1.109 2004/02/03 19:14:59 kirk Exp $
##########################################################################
# Most current version can always be found at:
# ftp://ftp.logwatch.org/pub/redhat/RPMS
..............
# Default config here...
$Config = 0;
$Config = "root";
$Config = "/tmp/logwatch";#改變默認配置,讓結果保存到文件
$Config = 0;
$Config = "yesterday";
$Config = 0;
$Config = 0;
$Config = "/tmp";
$Config = 0;
$Config = 0;
....................
sub send_mail
{
my($to,$from,$subject,@body)=@_;
my $relay="smtp.yourserver.com";#你用來發信的smtp server
my $smtp=Net::SMTP->new($relay);
die "Could not open connection: $!" if (!defined $smtp);
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
foreach(@body) {
$smtp->datasend("$_\n");
}
$smtp->dataend();
$smtp->quit;
}
..........................
#############################################################################
# Get rid of temp directory...
if ($Config<100) {
`rm -rf $TempDir`;
}
#自己加的,讀取文件的內容,然後發信給管理員
open(FILE,$Config);
my @tmp;
@tmp=
&send_mail("jiecho\@eyou.com","[email protected]","logwatch for you host",@tmp);
close(FILE);
`rm -rf $Config`;
#這段內容要在exit(0)前執行,放在後面的話程序沒有執行就退出了.
exit(0);
# vi: shiftwidth=3 tabstop=3 et