maillogs — Send log files by mail
maillogs
[
{ -f=user@domain
| --from=user@domain
}
] { --stdout | {
{ -t=user@domain
| --to=user@domain
}
...}} [
{ -s="subject
" | --subject="subject
" }
] [
{ -c=charset
| --charset=charset
}
] [{ -p=value
| --pattern=value
} { -P=value
| --utf8pattern=value
}] {statefile} {logfile...}
Everyone's too lazy to look at log files. maillogs reads some log files, and emails them to somebody, who will hopefully open their mailbox and read them.
maillogs expects to be executed regularly
(hint: cron.hourly
).
maillogs does not mail all the log files every time
it runs, only what it finds in each log file that wasn't there the last
time maillogs looked at it. The first non-option
parameter to maillogs is a file where
maillogs saves its state (creating it if necessary):
namely what it saw already. The remaining parameters are log files that
maillogs reads. Using shell wildcards is an
excellent way to handle log rotation:
$ maillogs [options] /var/mail.state /var/log/mail/*.log
Each time a new /var/log/mail/*.log
appears, maillogs picks it up and dumps it on someone's
desk.
maillogs cannot be used with applications that rotate log files by renaming them. maillogs expects the log file creator to create a new log file, each time, and remove the older ones.
maillogs expects each individual log file to consist
of a plain text file, one line per log entry.
By default, each time maillogs runs, it mails
every new line it finds in each file, since the last time
maillogs ran.
--pattern
or --utf8pattern
are
optional, and specify that only the individual lines matching the given
pattern, which gets specified using the same syntax as Perl
regular expressions (maillogs uses the
pcre library).
maillogs does not send any mail if it doesn't find anything new in any log file. Otherwise, the result is nothing fancy: just all the new/selected lines from all log files, concatenated.
Only one regular expression pattern can be specified. To select multiple patterns, try shoehorning them into a single regular expression. The alternative is to run maillogs separately, once for each pattern, giving the same log files, but a different state file. This, of course, results in a separate mail from each instance of maillogs.
-f, --from=user@domain
This parameter names the sender's address for the mail. This is optional, if not present maillogs lets sendmail figure it out.
-t, --to=user@domain
This parameter names the recipient's address. This parameter may occur more than once, to send the mail to multiple recipient. Each occurence of this parameter gives a single address.
--stdout
Do not send the mail, only format it and send it to standard output.
Either --stdout
, or at least one
-t, --to
option must be given.
-s, --subject="text
"
Set "text
" as the mail's subject.
-c, --charset="codeset
"
Specify "codeset
" as the mail's
MIME character set.
-p, --pattern="regexp
"
Mail only the individual lines of text that match the
"regexp
" regular expression, which
generally uses the Perl syntax for regular expressions.
The regular expression is not anchored, and can match any part
of each individual line in the log file.
Use “^” to anchor the regular expression to the
start of the line.
-P, --utf8pattern="regexp
"
An alternative of --pattern
that specifies that the regular expression
and all the log files are presumed to be coded in the
UTF-8
codeset. Requires that the
pcre library be compiled with
UTF-8
support (usually the case now).
maillogs runs /usr/sbin/sendmail
or the program specified by the SENDMAIL
environment
variable, to send the mail, unless
--stdout
is given.
--subject
does not MIME-encode non-Latin characters in
the mail's subject. You'll have to do it yourself.