[Top] [All Lists]

Incrementing a counter

1997-10-09 12:42:17
I'm again embarrassed by these simple questions:

I'm catching what I think is spam, extracting a few headers of the spam and
appending them to a summary file for review, and then once a day emailing
myself this summary of the day's spam.  The alleged spam gets gzipped for
later review, if desired.

I have a few questions.  Basically, I get confused on how to properly do
things in procmail that aren't actually dealing with the message.

1) I have a file that keeps track of the number of spams (an ID number that
I will use to extract a spam at a later date if desired).  I need to
increment it each time.

      # Unset spam message counter

      # lock here
         * ? test -f $PMDIR/spamcount
         { MESSAGENUM=`cat $PMDIR/spamcount` }

         # reset to zero if not set

         # is this the best method to increment,
         # or would procmail scoring be better?

         MESSAGENUM=`expr $MESSAGENUM + 1`

         # write the incremented count back out
         # Is this DUMMY method a good way to execute commands?
         DUMMY= `echo $MESSAGENUM > $PMDIR/spamcount`

So is that a good way to increment, or would a scoring recipe be better?

        * $MESSAGENUM^0
        * 1^0
        { }
        MESSAGENUM = $=

2) This is where I get confused.  I want to append some extracted headers
from the current mail to a file.  I don't want to alter the current mail.

Is it better to use the DUMMY method as:

        DUMMY=`echo Message Subject: $SUBJECT >> summary.spam`
        DUMMY=`echo           Date:  $DATE >> summary.spam`

What bothers me is doesn't procmail provide the current mail to STDIN of
the external command?  Is it better to do something like

     | (echo "Message Subject: $SUBJECT; \
       echo "           Date: $DATE; \
       echo "          MsgID: $MESSAGEID; \
       echo "Rejected Reason: $REJECT_REASON; \
       echo " ") >> summary.spam

3) How do I compare two variables?  Now this is embarrassing and clunky:
I want to mail my spam summary at the start of each day.  When I get my
first message of the day I see if the current date is the same as I have
recorded in a file.  (Easier way?  is there a simple way to just look at
the actual summary.spam file date and then mail it if it isn't today's date.)

   TODAY=`date '+%m%y%d'`

   # Unset $CURRENT

   # Read current date from the file, and compare with TODAY
   * ? test -f $PMDIR/currentdate.spam
      CURRENT=`cat $PMDIR/currentdate.spam`

      # lock so we don't try to mail the message more than once

      * ! $ CURRENT ?? $TODAY
         # update the current date as today
         DUMMY=`echo $CURRENT > $PMDIR/currentdate.spam
         # now send yesterday's spam summary
         * ? test -f $PMDIR/summary.spam
            DUMMY=`cat $PMDIR/summary.spam | mail moseley`
            DUMMY=`rm %PMDIR/summary.spam`

My questions:

 - Is that the proper place for a lockfile?

 - How should I compare the current date with the date in the file.
   Would it be better to grep TODAY against currentdate.spam?

 - What's the best way to mail a file to myself?  Do I need to WAIT for
   the mail command to finish before removing the file?

 - Is   * ! $ CURRENT ?? $TODAY the correct syntax?  Do I need the first "$"
   expand $TODAY?

Thanks ever so much.

Bill Moseley

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