procmail
[Top] [All Lists]

Re: Avoiding unnecessary call

2001-01-07 13:48:52
Rejo Zenger <subs(_at_)sisterray(_dot_)xs4all(_dot_)nl> writes:
++ 06/01/01 15:40 -0600 - Philip Guenther:
...
I also quoted the match in the grep command.  That'll keep the shell
from trying to perform filename expansion on the pattern argument to
the grep command.  Hmm, You could actually get a false match there if
two newsgroups differ by a dot, or if one is a substring of another.
We would need to know more about the format of the stemmingen.txt file
to fix that.  Knowing your version of grep (or OS) may make that
easier.

$ uname -sr
Linux 2.2.16

$ grep -V
grep (GNU grep) 2.4

Good, your grep has the -q flag, so we can save a shell process by using
it instead of the ">/dev/null".  


$ cat vote/current/stemmingen.txt 
GROEP                           START           EIND            DUUR    NOTES 
(V:T:B:O)
nl.actualiteiten                2000-08-13      2000-09-09      4w      
Cancelled op 2000/08/15.
nl.muziek.instrument.toetsen    2000-08-13      2000-09-09      4w      
Aangenomen 74:11:3:6
...
The fourth column are the number of weeks the CFV is running and is needed
by other scripts. The last column is relevant for us, as that one will be
used to determine if a voting is running. It is, like the last two, it will
have the word Running there, otherwise other words will indicate the current
state.

Votings at the same time for groups that differ by only a dot is extremely
rare, however votings for newsgroups of which one is a substring of the
other, that could be possible.

Please note, i can change the order of the columns if needed. I guess it
will be made a lot eassier if the GROUP and NOTES are next to each other so
one can test for whitespace only between the groupname and Running. Correct?

No need for that, we can just make sure the newsgroup name is followed by
whitespace and the "Running." is preceeded by one:

        :0
        * ^Envelope-To: stemformulieren(_at_)sisterray\(_dot_)xs4all\(_dot_)nl
        * ^Subject: .*\/nl\.[-a-z_0-9.+]+
        {
            # Build a regexp to match the correct line.
            # The $\variable syntax escapes egrep-style regex metacharacters
            # and tacks "()" on to the front.  For example, if the newsgroup
            # name in MATCH were "nl.comp.lang.c++", then this would expand
            # to "^()nl\.comp\.lang\.c\+\+[     ].*[    ]Running\."
            # Note that this expansion _must_ be used with egrep and not grep:
            # parens aren't magical to grep, but \+ is!

            regex = "^$\MATCH[  ].*[    ]Running\."


            # The -q flag to egrep tells it to not print anything, just
            # set its exit code.
            :0
            * ? egrep -iq "$regex" ${VOTEDIR}/stemmingen.txt
            {
                :0 c:
                $VOTEDIR/$MATCH/backup/votes

                :0:
                $VOTEDIR/$MATCH/votes
            }
        }


Philip Guenther
Procmail Maintainer
_______________________________________________
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>