Skip to main content
Invert meaning of zero / non-zero is latter examples
Source Link
tripleee
  • 8k
  • 2
  • 37
  • 45

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

If you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probablyobviously need to invertchange the logic of your script so that its exit code is the inverse of what it is now.)

In case you want the syntax sorted out for you, here is a more general attempt at doing what you seem to think you were doing:

:0 ? ! script ! somewhere 

which will forward to somewhere if the exit valuecode of script is non-zero;zero (as in success); or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is not zero :0 * ! ERR ?? ^^0^^ ! $WHERE 

(Several arcane details of uncommon Procmail syntax are present here. The ?? operand examines the value of the named variable; the ^^ anchor matches beginning / end of input string.)

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

If you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probably need to invert the logic of your script so that its exit code is the inverse of what it is now.)

In case you want the syntax sorted out for you, here is a more general attempt at doing what you seem to think you were doing:

:0 ? ! script ! somewhere 

which will forward to somewhere if the exit value of script is non-zero; or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is not zero :0 * ! ERR ?? ^^0^^ ! $WHERE 

(Several arcane details of uncommon Procmail syntax are present here. The ?? operand examines the value of the named variable; the ^^ anchor matches beginning / end of input string.)

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

If you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will obviously need to change the logic of your script so that its exit code is the inverse of what it is now.)

In case you want the syntax sorted out for you, here is a more general attempt at doing what you seem to think you were doing:

:0 ? script ! somewhere 

which will forward to somewhere if the exit code of script is zero (as in success); or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is zero :0 * ERR ?? ^^0^^ ! $WHERE 

(Several arcane details of uncommon Procmail syntax are present here. The ?? operand examines the value of the named variable; the ^^ anchor matches beginning / end of input string.)

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 
Rearrange so that "the right solution" comes first
Source Link
tripleee
  • 8k
  • 2
  • 37
  • 45

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

Now, based on your description of whatIf you actuallyjust want to accomplishdiscard the message altogether if your script returns success, you arecan try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probably lookingneed to invert the logic of your script so that its exit code is the inverse of what it is now.)

In case you want the syntax sorted out for somethingyou, here is a more likegeneral attempt at doing what you seem to think you were doing:

:0 ? ! script ! somewhere 

which will forward to somewhere if the exit value of script is non-zero; or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is not zero :0 * ! ERR ?? ^^0^^ ! $WHERE 

(Several arcane details of uncommon Procmail syntax are present here. The ?? operand examines the value of the named variable; the ^^ anchor matches beginning / end of input string.)

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 

On the other hand, if you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probably need to invert the logic of your script so that its exit code is the inverse of what it is now.)

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

Now, based on your description of what you actually want to accomplish, you are probably looking for something more like

:0 ? ! script ! somewhere 

which will forward to somewhere if the exit value of script is non-zero; or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is not zero :0 * ! ERR ?? ^^0^^ ! $WHERE 

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 

On the other hand, if you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probably need to invert the logic of your script so that its exit code is the inverse of what it is now.)

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

If you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probably need to invert the logic of your script so that its exit code is the inverse of what it is now.)

In case you want the syntax sorted out for you, here is a more general attempt at doing what you seem to think you were doing:

:0 ? ! script ! somewhere 

which will forward to somewhere if the exit value of script is non-zero; or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is not zero :0 * ! ERR ?? ^^0^^ ! $WHERE 

(Several arcane details of uncommon Procmail syntax are present here. The ?? operand examines the value of the named variable; the ^^ anchor matches beginning / end of input string.)

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 
Source Link
tripleee
  • 8k
  • 2
  • 37
  • 45

Let's examine your action:

:0 ! `script` 

The meaning of the backticks is "use the output of script as a string here". So if your script outputs [email protected] then the recipe will effectively be equivalent to

:0 ! [email protected] 

which means to forward the message to [email protected]. The behavior you describe should thus not be surprising at all; Procmail is doing precisely what you are telling it to do.

Now, based on your description of what you actually want to accomplish, you are probably looking for something more like

:0 ? ! script ! somewhere 

which will forward to somewhere if the exit value of script is non-zero; or possibly

# Capture the output from script in WHERE WHERE=`script` # Also capture its exit code ERR=$? # Forward to $WHERE if $ERR is not zero :0 * ! ERR ?? ^^0^^ ! $WHERE 

If your script is no more complex than that, you might as well inline it. (Notice the syntax fix with a dash before the i option, and the inversion of the exit status with !):

:0 * ! ? grep -i "$SENDER" /home/foo/scripts/blah/blah2.txt ! somewhere 

On the other hand, if you just want to discard the message altogether if your script returns success, you can try this trick:

:0W | script 

This is basically the same as the formail -D example for suppressing duplicates; if the script returns a success exit status, the message is considered delivered; but since the script doesn't actually deliver it anywhere, it is actually lost. (You will probably need to invert the logic of your script so that its exit code is the inverse of what it is now.)