不懂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","admin@yourhost.com","logwatch for you host",@tmp);
close(FILE);
`rm -rf $Config`;
#这段内容要在exit(0)前执行,放在后面的话程序没有执行就退出了.
exit(0);
# vi: shiftwidth=3 tabstop=3 et