From: Hans C. <fo...@gm...> - 2018-09-30 01:54:36
|
I ended up adding a few lines to the fetchmail source (see below). Someone a bit more enterprising than me could probably submit a patch with some kind of config file option (eg. log_timestamp) to do something similar. This makes the log entries look like this: fetchmail [2018/09/29 17:04:41]: 2 messages for ... fetchmail [2018/09/29 17:04:42]: reading message ... Here's the patch I used for 6.3.26... diff -ur fetchmail-6.3.26/report.c fetchmail-6.3.26-new/report.c --- fetchmail-6.3.26/report.c 2013-04-23 13:00:45.000000000 -0700 +++ fetchmail-6.3.26-new/report.c 2017-09-28 23:25:10.443642824 -0700 @@ -125,13 +125,20 @@ else /* i. e. not using syslog */ #endif { + time_t now; + static char timebuf[20]; + if ( *message == '\n' ) { fputc( '\n', errfp ); ++message; } if (!partial_suppress_tag) - fprintf (errfp, "%s: ", program_name); + { + time(&now); + strftime (timebuf, sizeof(timebuf), "%Y/%m/%d %H:%M:%S", localtime(&now)); + fprintf (errfp, "%s [%s]: ", program_name, timebuf); + } partial_suppress_tag = 0; #ifdef VA_START On Sat, 29 Sep 2018, Gene Heskett wrote: > 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 ghe...@sh...@pop.shentel.net:1 of >>> 1 (8044 octets) flushed >>> >>> to: >>> >>> fetchmail: reading message ghe...@sh...@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 >> > I see, this last looks to be more promising. Looks like the date/time > would be prepended, the src of the line would be intercepted so the > extra data can be prepended. > >> 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. > > Been known to do that many times in the past, but time has taken its toll > on my thinker. >> >> G'luck, >> Peter > > Thank you Peter. > > |