procmail
[Top] [All Lists]

Re: COUNT

2001-07-24 17:07:22
Aaron suggested to KJ,

That's a lot of processes.  It should be possible to do it without any
additional processes.  The following code is completely untested, but it
should work.

It is very similar to code I've used, so I'll second Aaron's "it should
work."

# Get a regional lock
LOCKFILE=count.lock

Since the INCLUDERC is going to be named .count and not count, better to
keep that leading period in the lockfile's name as well; what if KJ has a
folder named "count" some day?  So let's make that,

 LOCKFILE=.count$LOCKEXT

# Get the old value for COUNT from .count
#  This file should have a line like "COUNT=1" (without the quotes)
INCLUDERC=.count

# Increment count using scoring
:0
* $COUNT^0

Better take Don's advice and do it this way in case for some reason $COUNT
doesn't get initialized; also, you need two dollar signs there: one to tell
procmail to substitute variables and one to mark $COUNT as a variable
instead of literal text:

  * $ ${COUNT:-0}^0

* 1^0
{ }
COUNT=$=

One problem: the next routine will make the .count file grow and grow as new
values of COUNT are appended with each incoming message for which procmail
runs the routine, slowing procmail down and taking up disc space.  So let's
make it trim itself every so often while we still have the regional
lockfile:

 :0ci # whenever the count is a multiple of 100, zap the accumulated
      #assignments from .count
 * COUNT ?? 00$
 | rm -f .count

and then we finish with the rest of Aaron's code:

# Write new count to .count by temporarily redirecting log messages
oldLOG=LOGFILE
LOGFILE=.count
LOG="COUNT=$COUNT
"
LOGFILE=$oldLOG

# Done, so regional lock can go away
LOCKFILE

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

<Prev in Thread] Current Thread [Next in Thread>