procmail
[Top] [All Lists]

Re: running "Side effect" shell commands

1998-02-04 03:19:04
Tue 98-02-03 dattier(_at_)wwa(_dot_)com (David W. Tamkin) list.procmail
| | 
| |     :0
| |     *   in-some-cases-go-here
| |     * ? echo "$TODAY $FFROM $FSUBJ" >> $HIN
| |     { }

The reason I was asking, was that when I was about to drop a message to
a folder I wanted to write a message to my Emacs biff log too. While
experimenting with all these I started with this:

    :0
    * drop-condition
    {

        # or use this as david suggest, it's more correct, uses file locking.
        #   :0 wic:
        #   | echo "folder: work-xxx" >> $biff
        #

        #   This was shorter than above, so I settled with this for a long time
        dummy = `echo "folder: work-xxx" >> $biff`

        :0 :
        $MBOX_WORK_XXX
    }


But i found it tedious to duplicate similar recipe for every mailbox.
Okay, I now realize that I could have used INCLUDERC to make that part
a subroutine, but it would still have been rather lenghty and I'm not
sure it it would have shortened the recipe much (setting up INCLUDERC
values before calling, adding the INCLUDERC = statement and so forth..)

So I come by with idea

    :0
    * drop-condition
    * ? echo "folder: work-xxx" >> $biff
    $MBOX_WORK_XXX

Which is significantly shorter. You must look at the recipe in two parts:
the drop conditions are over "?" token, and what happen on "?" line is
just a syntatic sugar and has nothing to do with the drop conditions.

the "?" trick only allows running some additional shell commands
(echo is one that always succeeds) while conditions above have already 
determined that drop will take place. And you can always make condition
to succeed with:

    * ? misbehaving-shell-script || echo

If "misbehaving-shell-script" always return failure exit code.

If I would have surround this last recipe with LOCKFILE, which would
have been the correct thing (tm), I would have had to do it for every
recipe.

Guess what :-) I think I keep being lazy and leave out the LOCKFILE in
these cases and bear the fact that there may be collision some
times. Besides the writes are buffered usually in unix, so I assume
that writing to unlocked file, which data is not important, would
go there just fine.  Not necessarily in the right order of course if
there is some other write call in progress at the same time. I can
bear with it...

jari