procmail
[Top] [All Lists]

Re: pipe a mail to more than one program

1999-11-22 07:04:44
On Mon, 22 Nov 1999 13:04:17 +0000 (GMT), James Stevenson
<mistral(_at_)stevenson(_dot_)zetnet(_dot_)co(_dot_)uk> wrote:
what i would like to do is to
:0
|program1
|program2
mailbox

Depending on what program1 and program2 do, you may be able to string
them together if you can modify them so they also print their standard
input back to standard output.

    :0:
    | program1 | program2 >>mailbox

Or if you can't do that, you can use a temporary file:

    #!/bin/sh

    TEMP=/tmp/$$.temporariness
    trap 'rm -f $TEMP' 1 2 15

    tee $TEMP
    program1 <$TEMP  #>/dev/null  # (you may need to discard stdout)
    program2 <$TEMP  #>/dev/null  # ditto
    rm -f $TEMP

    # perhaps this should return some sort of useful exit code

Save that as, say, $HOME/bin/program1+2, and change your recipe to
pipe into that (fix Procmail's PATH if necessary):

    :0:
    | program1+2 >>mailbox

You could inline more or less the same script directly on the action
line in your .procmailrc but that's a bit cumbersome in the long run.

    TEMP=/tmp/$$.temporarity
    TRAP="rm -f $TEMP"
    :0: # not what you want if programX prints something to stdout!
    | ( tee $TEMP ; program1 <$TEMP ; program2 <$TEMP ) >>mailbox

If you want to get fancy, there's a program called multitee somewhere
out there which does something somewhat related to this, too.

and also what is the difference between
:0
and
:0 :

One is what you do when you have read the FAQ, and the other is not. :-)

  <http://www.iki.fi/era/procmail/mini-faq.html>

The second colon says to use a lock file. That's in the manuals. What
isn't in the manuals is a good explanation of what lock files are
supposed to accomplish and when you should use them. The FAQ attempts
to explain this a little bit. I also tried to submit an explanation 
for the lockfile(1) manual page to procmail-dev at one point but it
doesn't seem to have made it into the new 3.14 release candidate. Oh
well.

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

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