Re: how to log date/time in daemon mode?

Peter Pentchev <[email protected]>
Newsgroups gmane.mail.fetchmail.user
Message-ID <[email protected]>
On Sat, Sep 29, 2018 at 02:17:55PM -0400, Gene Heskett wrote:
> On Saturday 29 September 2018 13:10:49 Juergen Edner wrote:
> 
> > Hi Gene,
> >
> > > I was subjected to a phishing attack yesterday and again today, and
> > > it would have been a lot easier to correlate the messages if
> > > fetchmail was logging the time, preferably the date/time at the end
> > > of fetching of fetching each mail. Something it is not now, and
> > > never has done.  And I just reread the man pages without finding a
> > > clue.
> > >
> > > How do I enable this so a date/time exists in the fetchmail.log?
> >
> > I'm using the following two commands to log the start and end of
> > request cyle:
> >
> > preconnect  "echo 'fetchmail: awakened at '`date +'%a, %d %b %G
> > %H:%M:%S (%Z)'`"
> >
> > postconnect "echo 'fetchmail: sleeping at '`date +'%a, %d %b %G
> > %H:%M:%S (%Z)'` for xxx seconds
> >
> THis would triple the size of the log in terms of line count. What I 
> would really like to do is convert the single log line:
> 
> fetchmail: reading message [email protected]@pop.shentel.net:1 of 1 
> (8044 octets) flushed
> 
> to:
> 
> fetchmail: reading message [email protected]@pop.shentel.net:1 of 1 
> (8044 octets) flushed 09/27/18 14;51.28

This could be done if you pipe fetchmail's output through some other
program that puts a timestamp on each line; multilog, the log processor
from the daemontools package, comes to mind, but in a pinch this might
be done with a small dedicated program, maybe something like this:

#!/usr/bin/perl

use 5.012;
use strict;
use warnings;

use POSIX qw(strftime);

while (<>) {
	print strftime('%Y-%m-%d %H:%M:%S', localtime)." $_";
}

...or even something like:

#!/bin/sh

while read line; do
	printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"
done

But, yes, I do see your point that fetchmail could also do it by itself,
although sometimes chaining a couple of tools is a good approach.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} [email protected]
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

_______________________________________________
Fetchmail-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fetchmail-users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAluwCxsACgkQZR7vsCUn
3xPflhAAqQewcTLXwwYX2EhvtglDejxODM+8OEuHthoDtDbBvPi54SKmYHDlG/c6
fjlDV84jHVHzze60WbWxNcYGpPWey9gzubDkt/oRYb6DEq8iLEh3xmxvQxTR5Auo
slSx1eiSMhhfy49VHZbfErHFJzYx3hDZlaWhsUKuHYRkHh4PInSFBn5p6wvyJ8vY
Fn4NB1ZibB6jsWiOtJh2UMfGuDByZ+hUBBOj7yM0XbdVwM4wDbnF0R9HhNKO0qKF
AIiyIOiR6a+Ro+c1IvrJQmNN0sJHGYJP0atEvmGb/wS3GOoMi7vRQLg83Or25mJM
VFYNTwqcvXycpm7TqeCmQRrUPwUEWNYxOCR0c0XtyZmR5Zr3NcwEOfIyrHeJ/Vby
aJ1ABL/ygREQ1lcvfz0jvbvEp75mpPNQTK+5craETQ97T5irRhhlUyCRZglyQ9Th
zempGfSjSl09+gfOslStA+QoFhWFsq9vAVHSrmjoRt7yzkpHfJKgUfcdguAiFxOY
XmV+DIjiT5IUcy/4mhtMzFOI5iwPHMnTj1n0iuSPKt74OXYZ4RpB00alAssYi2KS
v58j7NkMIbVFY8paFEjpmzGzsNMnx5GZ4INvK3jeheGMylk6vAt+J350tpvjVIeR
OjbATRjWM/XzQ+lbIFQl+5J/ww10zEXvs3mfGMywNOMQetjyx9g=
=tM9S
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.