procmail
[Top] [All Lists]

Re: running "Side effect" shell commands

1998-02-11 15:28:16
I've been meaning to answer this post from Jari for a long time:

| 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 the script *always* returns a failure code, just do this:

      * ! ? misbehaving-shell-script

The more complex case is a script that can return either success or failure
but you don't care which; if the drop conditions passed, you want to run
the action line.

Echo can also fail if the process lacks permission or opportunity to write
to stdout.  A more reliable choice is true(1); its purpose in life is to do
nothing but exit with status 0.  However, there is yet a better way to make
sure that a failure by the script doesn't make procmail abort the recipe:

  :0 flags
  * other conditions
  * 1^1 ? misbheaving-shell-script # s/b "misbehaving" but I like the typo
  action

Regardless of the exit status of the script, the condition will score 1 and
not interfere with procmail's decision about the action line of the recipe.

Weighted exit code conditions behave like this (see the procmailsc(5) man
page):

  * w^x ? command

scores w on success or x on failure.

  * w^x ! ? command

scores the same as this:

  * w^x  pattern_that_appears_in_the_search_area_$?_times