Import Debian changes 4.92-8+deb10u4
[hcoop/debian/exim4.git] / debian / syslog2eximlog
CommitLineData
de45f55a
AM
1#!/usr/bin/perl -w
2#
3# Copyright (c) 2003 Martin A. Godisch for Debian GNU/Linux, GPL
4
5=head1 NAME
6
7syslog2eximlog - make syslog output suitable for eximstats
8
9=head1 SYNOPSIS
10
11B<syslog2eximlog> B<<> I<mail.log> B<|> B<eximstats>
12
13=head1 DESCRIPTION
14
15syslog2eximlog converts logfiles produced by syslog when using
16B<log_file_path = syslog> in your I<exim.conf> back to exim
17logfile format, suitable for B<eximstats>. B<syslog_timestamp>
18may be B<true> or B<false>.
19
20The program always succeeds, invalid lines will be ignored.
21
22=head1 BUGS
23
24Please report any bugs directly to the author.
25
26=head1 AUTHOR
27
28Martin A. Godisch <godisch@debian.org> for Debian GNU/Linux.
29
30=head1 SEE ALSO
31
32B<eximstats>(8)
33
34=cut
35
36my @date = localtime(time);
37$date[4] += 1;
38$date[5] += 1900;
39my %names = (
40 "Jan", "01", "Feb", "02", "Mar", "03", "Apr", "04",
41 "May", "05", "Jun", "06", "Jul", "07", "Aug", "08",
42 "Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12"
43);
44
45while (<>) {
46 next unless (s/^(\w{3})\s([\s\d]\d)\s(\d\d):(\d\d):(\d\d)\s\S+\sexim\[\d+\]:\s//);
47
48 my ($month, $day, $hour, $min, $sec) = ($names{$1}, $2, $3, $4, $5);
49
50 if (/^\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d\s/) {
51 print $_;
52 } else {
53 printf "%04d-%02d-%02d %02d:%02d:%02d %s",
54 # assume current year if month/day <= today, otherwise assume last year
55 $month > $date[4] || $month == $date[4] && $day > $date[3] ? $date[5] - 1 : $date[5],
56 $month, $day, $hour, $min, $sec, $_;
57 }
58}
59
60exit 0;