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

Gene Heskett <[email protected]>
Newsgroups gmane.mail.fetchmail.user
Message-ID <[email protected]>
On Saturday 29 September 2018 19:30:41 Peter Pentchev wrote:

> 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,
Got that, but will try to understand the manpage tomorrow

Thank you.

> 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



-- 
Cheers, Gene Heskett
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
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.