[Logwatch] logwatch suggestion

Bob Hutchinson hutchlists at midwales.com
Fri Jul 8 08:27:12 MST 2005


On Friday 08 Jul 2005 12:08, Pan, Aguang wrote:
> Dear Sir,
>
>    Our company is using Linux for E-mail and of course the logwatch written
> is great tool. However we have a small problem when using this logwatch
> file. Because we have so many E-mails everyday so the logwatch can not send
> the check result but send an E-mail with the below errors:
>
>     /etc/cron.daily/00-logwatch:
> postdrop: warning: uid=0: File too large
> send-mail: fatal: root(0): Message file too big
>
>    I am wondering it is possible for the logwatch to write everything to a
> file and then send that file instead of putting check result in the message
> body?

set the 'Save' variable in logwatch.conf will put the output into a file
attaching it to an email is another matter, but Perl does have libraries that 
will do this, eg MIME::Lite

here is a perl subroutine that will get you started
sub send_attach_mail
{
        # Usage:
        #               $OK = &send_attach_mail($to,$from,$subject,$body,
$file,$type,$encoding);
        #               $file,$type,$encoding are optional
        #               returns true if succesful.
        # requires MIME-Lite perl module

        use MIME::Lite;
        my $to       = shift(@_);
        my $from     = shift(@_);
        my $subject  = shift(@_);
        my $body     = shift(@_);
        my $file     = shift(@_);
        my $type     = shift(@_);
        my $encoding = shift(@_);

        my $msg = MIME::Lite->new(
                Type    =>'TEXT',
                From    => $from,
                To      => $to,
                Subject => $subject,
                Data    => $body);
        # attach if there is one
        if($file)
        {
                if(! $type )
                {
                        $type = 'application/octet-stream';
                }
                if(! $encoding )
                {
                        $encoding = 'base64';
                }

                $msg->attach(
                        Type     => $type,
                        Path     => $file,
                        Encoding => $encoding);
        }

        # get rid of mime-headers
        $msg->scrub;
        open(SENDMAIL, "|/usr/lib/sendmail -t -oi -oem") or die("$0: open 
sendmail: $!\n");
        $msg->print(\*SENDMAIL);
        close SENDMAIL;
        die("sendmail failed: $!\n") if ($? >> 255);
        return(1);
}
#######


HTH
-- 
-----------------
Bob Hutchinson
Midwales dot com
-----------------


More information about the Logwatch mailing list