At 13:35 2010-11-25, Emmanuel Buamah wrote:
My question is, how do I check the exit code of the script and take
an action on it?
As a condition, or as a filter? If as a filter, do you only need
true/false granularity, or to act upon a specific value?
:0fw
| some_script
Would filter the message and wait for the exit code - if it isn't 0
(success), then it treats the message as if the recipe hadn't been
invoked and reverts to the original (unfiltered) message.
:0
* ? some_script
mailbox
Would pump the headers of the message (unless you added hb or b to
the flags line, or H or B to the condition line) into the script and
use the exit code as an inverted true/false (exitcode = 0 = true, any
nonzero, false) for evaluating the condition.
If you invoke a pipeline this way, such as:
* ? grep username | grep something
the exitcode which is evaluated is the one returned by the last
program in the pipeline.
If you want the actual value to subsequently evaluate, then:
DUMMYVAR=`some_program args`
SOME_PROGRAM_EXITCODE=$?
Note that this is outside of a recipe (though it could be within a
braced section).
This is not to be confused for condition lines which may have $? at
the beginning, which would evaluate shell variables and examine the
return value (but isn't an assignment). You'd want to assign the
value to a variable so that you could evaluate it in a condition
without the exitcode variable being evaluated as a pair of
flags. You can use scoring to do math for checking whether the
variable exceeds a certain value.
:0
* -25^0
* $ $SOME_PROGRAM_EXITCODE^0
mailbox
Would evaluate as true if the saved exitcode exceeded 25.
If you just want to match a specific value:
:0
* SOME_PROGRAM_EXITCODE ?? ^25$
mailbox
If you wanted to match for 25 exactly (or ^^25^^ would work).
---
Sean B. Straw / Professional Software Engineering
Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
Please DO NOT carbon me on list replies. I'll get my copy from the list.
____________________________________________________________
procmail mailing list Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail