Welcome to Aaron Thompson's Page Sunday, February 12 2012 @ 03:25 CST  
Personal
Contact Info
Family
Resume
 
Development
CGI
probability project
 
Perl Modules
Win32::AD::User (cpan)
 
Shell
backup_file (source)
chkconfig (source)
gen-autohome (source)
group-utils (source)
mail-deny (source)
mail-logs (source | archive)
mailman-qmail (source)
qmail vacation (source)
 
Links
Beast of Burden LLC
Central Iowa LUG
CedarLUG
CedarvalleyPM
ITS-IS Home
ITS Home
UNI Home
 
 

Name

mail-logs.pl -- email logs for the previous day.

Version
  v0.4
Synopsis
  mail-logs.pl
Description

mail-logs.pl provides a simple way to extract your logs from the previous day and deliver them to any email address.

The mail-logs.pl was created to help ensure that the logs were checked, and archived every day. Email delivery allows multiple people the ability to read thru the log with out requiring access to the files. Also the email messages provide a 'backup' of the log files.

Options

mail-logs.pl does not accept any command line options. It parses log files defined in the script and delivers an email for each log file to the address specified.

Configuration

Requirements for the script are described in the comments found at the beginning of the script. Basically you will need to make sure the following commands are available: dnsdomainname, hostname, date, and ls. Also the perl module Net::SMTP needs to be properly setup for this script to work.

Bellow is a description of the various variables that need to be defined or setup for the script to function properly.
  @logFiles
    logFiles is a list standard syslog log files to be parsed. When defining
    this do not worry about logs rotated using logrotate - this script should
    parse those logs also... for example if "/var/log/syslog" is specified
    /var/log/syslog* will be parsed and included in the same message, as long
    as they are either plain text or gziped plain text.
  
    Here is an example email using /var/log/mail.warn in @logFiles:

      ---<tmp.msg>---
      To: thompson@cns.uni.edu
      From: mail-logs@server.cns.uni.edu
      Subject: server.cns.uni.edu /var/log/mail.warn Jun 29
  
      /var/log/mail.warn
      =====================================
      Jun 29 12:09:25 server imapd[11375]: pam_ldap: [...]
      Jun 29 12:09:25 server imapd[11376]: pam_ldap: [...]
      Jun 29 21:26:35 server imapd[16266]: pam_ldap: [...]
      
      /var/log/mail.warn.0
      =====================================
      Jun 29 03:28:56 server imapd[5837]: pam_ldap: [...]
  
      /var/log/mail.warn.1.gz
      =====================================

      /var/log/mail.warn.2.gz
      =====================================

      /var/log/mail.warn.3.gz
      =====================================
      ---<tmp.msg>---

    When defining @logFiles each file name (or file-base name) should be double
    quoted string. Following basic perl list definition rules.

    The default value for @logFiles is:
      ("/var/log/messages",   "/var/log/syslog",
       "/var/log/kern.log",   "/var/log/auth.log",
       "/var/log/daemon.log", "/var/log/user.log",
       "/var/log/vsftpd.log", "/var/log/mail.err",
       "/var/log/mail.info",  "/var/log/mail.log",
       "/var/log/mail.warn",  "/var/log/uucp.log");

  $server
    The $server is used to define which SMTP server to connect to 
    when sending the email. Give the full DNS name. Use host or dig
    to find your DNS name.

  $mailTo
    $mailTo is the email address that will receive the messages for each log
    file. Currently mail-logs.pl does not support more than one email
    address to be defined here. Define an email list to contain the various
    people that should receive a copy of the mail messages. 

  $mailFrom 
    Use this to change who is listed on the "From:" line in your email
    headers. By default the script uses "mail-logs\@$hostname";

  $subject
    The $subject found in the main part of the application is currently 
    ignored. The subject is currently defined in the mailLogs sub-program.

  $message  = ""; 
    The $message found in the main part of the application is currently
    ignored. $message is re-written for each logFile in the mailLogs 
    sub-program.

  There are a few other system services that do not use the syslog standard log
  file format these services each have their own sub-program which may require
  configuration on its own.
  
    sub-program       Service Description
    -----------------------------------------
    mailBruLogs       Bru backup application logs. 
    mailSMBLogs       Samba file sharing services.
    mailAide          aide trip wire files.

Report a Bug

If you find a bug please let me know email me at thompson@cns.uni.edu.

Download / Source

Copyright (C) 2003 Aaron Thompson
thompson@cns.uni.edu

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. or visit http://www.gnu.org/copyleft/gpl.html

Click here to view the source code online

Click here to download the script