procmail
[Top] [All Lists]

Re: running commands from procmail

1998-08-20 00:35:13
On Mon, 17 Aug 98 16:49:55 -0400, Jerry Shenk <jas(_at_)dect(_dot_)com> wrote:
I'm having trouble getting this to work....spent a good bit of time
on it this weekend and today to no avail. I have the logging set to
verbose and everything looks like it makes sense - the Match shows
up correctly and the formail line has everything expanded out
correctly (doesn't show the intended recipient - not sure if it
should). The | $SENDMAIL -t line seems to be the problem...the
message never goes out.

Here's the standard response to this, but see below for something more
interesting, for which I'm Cc:ing this to the list also.

Try to replace Sendmail with >>/tmp/test (and add locking to the
recipe) to see if what gets piped to Sendmail looks like it makes
sense. (Or maybe even | tee -a /tmp/test | $SENDMAIL $SENDMAILFLAGS -t
and either fake it without locking of /tmp/testfile or use
:0:/tmp/test.lock ... and of course remember to clean up after
yourself when you're done debugging :-)

One question I had was on the formail line - Is that supposed to end in a 
'\' and the next line start with '| $SEND' or did the e-mail message wrap 
them?

It's supposed to look like that, i.e. 

   :0
   * condition
   * more conditions ...
   | action \
     rest of actions ...

Here comes the slightly more interesting part:

:0  # DON'T USE THIS VERBATIM. See improved regex below.
*   ^Subject:[      ]*ping[  ]*\/[-a-z0-9_]+(\.[-a-z0-9_]+)*
* ! ^X-Loop: ping(_at_)dect\(_dot_)com
| ( formail -rt -I "X-Loop: ping(_at_)dect(_dot_)com" ; ping "$MATCH" ) \
| $SENDMAIL $SENDMAILFLAGS -t

You could also try to log some things in Procmail's log. I'll leave it
to you to figure out what exactly; however, here's a useful thing I
didn't even know was possible (gleaned it from Eli's recipes [*]):

    :0
    *   ^Subject:(***corrected regular expression here***)
    * ! ^X-Loop: ping(_at_)dect\(_dot_)com
    LOG=| formail -rt -I "X-Loop: ping(_at_)dect(_dot_)com"

    :0a
    | ( echo "$LOG"; ping "$MATCH" ) | $SENDMAIL $SENDMAILFLAGS -t

The interesting thing is that LOG= not only logs to the log file, but
also exports to the environment the last string written to the log
(i.e. $LOG contains whatever you last assigned to it. Makes perfect
sense when you see it like this, I had just never thought about it).

Here's more or less what you should be seeing (I'm using a slightly
different recipe for semi-obvious reasons):

 $ procmail VERBOSE=yes ./.prc <<HERE
From: ping test
HERE
 procmail: [1755] Thu Aug 20 09:55:11 1998
 procmail: Match on "^From: ping test"
 procmail: Assigning "LOG="
 procmail: Executing "formail,-rt,-I,X-Loop: ping(_at_)dect(_dot_)com"
 To: ping
 X-Loop: ping(_at_)dect(_dot_)com
 procmail: Locking "/h/3/ykiel/reriksso/scratch/pingtest.out.lock"
 procmail: Executing " ( echo "$LOG"; echo "Unfortunately, no ping on this 
host" ) >>$HOME/scratch/pingtest.out"
 procmail: Assigning "LASTFOLDER= ( echo "$LOG"; echo "Unfortunately, no ping 
on this host" ) >>$HOME/scratch/pingtest.out"
 procmail: Unlocking "/h/3/ykiel/reriksso/scratch/pingtest.out.lock"
   Folder:  ( echo "$LOG"; echo "Unfortunately, no ping on this host" )         
     17
 procmail: Assigning "EXITCODE=0"
 procmail: Executing "echo,EXITCODE: 0"
 EXITCODE: 0

(Notice how the headers generated by formail -rt conveniently end with
an empty line which ends up preserving one [but not two] trailing
newlines in the log entry. Quite convenient, quite by accident :-)

You don't really care what's in pingtest.out because the important
parts are already logged above, but I include it just for reference:

 $ cat ~/scratch/pingtest.out
 To: ping
 X-Loop: ping(_at_)dect(_dot_)com

 Unfortunately, no ping on this host

sendmail -oi -t should be able to parse out the recipient address from
the To: line above (of course, in this case, the address formail puts
there is bogus) and send it off. (For the record, sendmail -t looks at
To:, Cc: and Bcc: only if there's no overriding Resent-To or other
Resent-* etcetera.)

Hope this helps,

/* era */

[*] Ref: <http://www.iki.fi/~era/procmail/links.html#examples>

(If you use freaking Netscape, it will chop off the #examples part of
the URL, but just tack it back on after the page has been loaded.)

-- 
Bot Bait: It shouldn't even matter whether  (`')  Just  (`')  http://www.iki
I am a resident of the State of Washington   \/ Married! \/   .fi/~era/

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