Subject: Re: Saving mail counts HELP!

From: [email-masked] (David W. Tamkin)
Date: Thu, 20 Jan 1994 12:12:00 -0600 (CST)

Steve Conniff asked,

|    BTW, is anyone using the weighted average feature in the latest
| procmail???  I haven't seen too much discussion about it lately.
| What is the verdict?

I'm using it and I like it, but I'm using it very simply, only with ^0
as the multiplier.

| SHELL=/bin/sh
| MAILDIR=$HOME/Mail
| DAY_FOLDER="count/`date +%m_%d`"
|
| # Keep track of how many messages I get per day.
| :0ci
| | (test -e $DAY_FOLDER || echo "0" > $DAY_FOLDER )
|
| NEW_DAY_COUNT=`expr \`cat $DAY_FOLDER\` + 1`
|
| :0c
| | echo $NEW_DAY_COUNT > $DAY_FOLDER

I'm wondering if procmail is having trouble processing the definition of
NEW_DAY_COUNT because of the nested graves.  Here are a couple wild-guess
ideas:

1. Stick our friend the semicolon into it so that sh, rather than procmail,
   processes it:

   NEW_DAY_COUNT=`expr \`cat $DAY_FOLDER\` + 1 ;`

2. Split the work up differently so that there are no nested graves:

   # Keep track of how many messages I get per day.
   :0ci
   | (test -e $DAY_FOLDER || echo "0" > $DAY_FOLDER )
   # Are the parentheses and the quotes really needed there?

   OLD_DAY_COUNT=`cat $DAY_FOLDER`

   :0c
   | expr $OLD_DAY_COUNT + 1 > $DAY_FOLDER

In either case, I'd recommend using a global lockfile during the segment
because if two letters come in at very nearly the same time they could each
pick up the same old count and write the same new count, throwing your daily
total off by 1:

   LOCKFILE=$DAY_FOLDER$LOCKEXT
   # Keep track of how many messages I get per day.
   :0ci
   | (test -e $DAY_FOLDER || echo "0" > $DAY_FOLDER )

   OLD_DAY_COUNT=`cat $DAY_FOLDER`

   :0c
   | expr $OLD_DAY_COUNT + 1 > $DAY_FOLDER

   LOCKFILE

[Does clearing $LOCKFILE from the environment rm the global lockfile? 
 I think so but I never use global lockfiles.]

David W. Tamkin  P. O. Box 3284  Skokie IL  60076-6284
[email-masked]   MCI Mail: 426-1818   +1 312 714 5610