procmail
[Top] [All Lists]

Re: procmail writing vars to file

1999-04-08 21:30:44
tomcat(_at_)visi(_dot_)com writes:
...
For the incoming email, I want to put
the subject, date, and a var that I get
out of the body (the emailer has sent
me his email address) and write it to
a file, but not the .log file.  I tried
to pipe the vars to a file, but no go.
I put the line SHELL=/bin/csh in for the
first line - i think that means pipe will
work.  

Yikes.  SHELL=/bin/csh is usually the exact opposite of what you want
to do.  csh is so limited in it's scripting (it's much better as a
interactive shell than as a scripting tool) that I generally recommend
putting SHELL=/bin/sh at the top of your .procmailrc to avoid problems.


I tried the following, which I think tries
to run a shell script:

:0w:
* ^Subject:[    ]\/[^   ].*
| our-script -s "$MATCH" >>$HOME/BHmail_log

Q: does this pass in a variable to a script
named our-script? How would you pass in
multiple variables?  The script would just
write the variables to a file, using >>, right?

There's already a program that serves that purpose: echo.  You'll also
need the 'i' flag on the recipe to avoid problems due to the program in
the action (echo) never reading its input:

        :0 wi:
        * ^Subject:[    ]\/[^   ].*
        | echo "$MATCH" >>$HOME/BHmail_log

If you wanted to pass in multiple variables, just put them on the
command line.  Alternatively, you can make use of the fact that
procmail places all its variables in the environment, so that invoked
programs can just reference variables from the environment directly
rather than having to pass them all one by one on the command line.
(The exceptions are the punctuation and numeric variables like $?, $=,
$_, $1, $@, etc)



I cant quite get the following to work either
(It's from a faq)

:0 hic:    #   we don't necessarily need `w'
* condition
 | echo message: $FROM $SUBJECT >> $biff

If the 'biff' variable isn't set then the shell will give a syntax
error.  Also, those variables should probably be quoted.


:0 hi:  #   Or you could use this
* condition
dummy=| echo message: $FROM $SUBJECT >> $biff

This would be slower and more confusing than the above.  Avoid it.

For the things you've tried that haven't worked, have you looked in the
procmail log for error messages?  Have you tried setting VERBOSE=on
before the problem recipe to see the details of what procmail is
doing?


Philip Guenther

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