procmail
[Top] [All Lists]

Re: "Atomic" updates to the LOGFILE...

2002-07-26 14:58:23
On 26 Jul, Michael J Wise wrote:
| Don Hammond wrote:
| 
| [...]
| 
| > I assign a LOGPFX variable that includes PID ($$) for each message.
| > Every LOG="..." is then LOG="$LOGPFX ...".
| 
| Hmmm.
| 
|           % man date
|           % man 3 strftime
| 
| Aha!
| 
| How about this (which I'm gonna try):
| 
|       EPOCHSECONDS=`date +"%s"`
|       LOGPREFIX=$EPOCHSECONDS.$$
| 
| That should leave logprefix looking something like:
| 
|       1027708364.1234

If machine load is an issue, my *guess* is that extracting month day
and time from the envelope will save some resources over forking the
date program. Admittedly, your prefix is a little shorter, but that can
be fixed.

Yours: 1027708364.1234
Mine:  0725 17:16:11 24002

Squeeze the whitespace, eliminate the colons (which can be done easily
enough), and add a period before the pid and you get 0725171611.24002
which is 1 character longer only due to the longer pid.  It's still
going to sort "correctly" and be unique, unless you keep one log for a
year or more, and your pids happen to be identical when a message comes
in on that exact second a year hence. If it were me, I'd risk it.

| I think I could sort on that easily enough.
| 
| > ... except for the LOGABSTRACT.
| 
| Yeah.
| 
| > He could prepend a unique prefix to each log write, and create a
| > custom LOGABSTRACT that did the same,
| 
| Probably best to set LOGABSTRACT to 'no', emit the Subject line myself
| ('cause I already emit the From: line), and then use TRAP to emit the
| LASTFOLDER variable, plus a blank line (for most-of-the-time readability).
| Hmmm. 'This Could Work...'.
| 
|       TRAP='echo "$LOGPREFIX Folder: $LASTFOLDER"'
| 
| One minor problem is those nice, multi-line variables that I'm using
| nowadays, but most of you probably won't have that problem. Oh well.
| 

Unless I'm misunderstanding what you're getting at here, you can still
do multi-line variables. Simulated below ...

(The TRAP= line should be one long line, but I don't know what my mail
client will do with it.)

$ cat thisrc
DEFAULT = /dev/null

PFX="0725171611.24002"
TRAP='echo -e "$ENDITALL$PFX $ENVELOPE\n$PFX  Subject: $SUBJ\n$PFX   Folder: 
$LASTFOLDER"'

:0
* ^^\/From .*
{ ENVELOPE = "$MATCH" }

:0
* ^Subject: \/.*
{ SUBJ = "$MATCH" }

ENDITALL="$ENDITALL$PFX Some comment here 1\\n"
ENDITALL="$ENDITALL$PFX Some comment here 2\\n"
ENDITALL="$ENDITALL$PFX Some comment here 3\\n"

$ procmail ./thisrc <spam2.drh 
0725171611.24002 Some comment here 1
0725171611.24002 Some comment here 2
0725171611.24002 Some comment here 3
0725171611.24002 From Smartbiz7767e24(_at_)yahoo(_dot_)com  Fri Jul 26 09:33:16 
2002
0725171611.24002  Subject: Give away FREE CD's - earn $5K in 30 days!
0725171611.24002   Folder: /dev/null

I recall David Tamkin pointing out that using hard quotes with TRAP=
causes the variables within TRAP to be interpolated when it's executed,
which is what you want. You need soft quotes around the other
assignents, so escaping the backslash in each of those gets the "\n"
passed to TRAP correctly.

-- 
Reply to list please, or append "8" to "procmail" in address if you must.
Spammers' unrelenting address harvesting forces me to this...reluctantly.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail