Discussion:
procmailrc syntax
Zhiliang Hu
2016-10-28 20:07:27 UTC
Permalink
Although I used procmail for so long I never figure out what kind of
"script" rules it follows. For example in one of my rc script I try to
calculate a list file ("dist"):

DISTCOUNT=`grep -cv '^(' dist` -1

the calculation part fails, end up in the log:

procmail: Skipped "-1"

How can I get over this without getting it to external script for a simple
calculation like this?

Zhiliang
Patrick Shanahan
2016-10-28 21:12:20 UTC
Permalink
Post by Zhiliang Hu
Although I used procmail for so long I never figure out what kind of
"script" rules it follows. For example in one of my rc script I try to
DISTCOUNT=`grep -cv '^(' dist` -1
procmail: Skipped "-1"
How can I get over this without getting it to external script for a simple
calculation like this?
Definitely not a procmail syntax expert here, but... I believe you are
have a problem with grep syntax rather than procmail. The minus sign for
a grep parameter requires special handling.
--
(paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri
http://en.opensuse.org openSUSE Community Member facebook/ptilopteri
http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2
Registered Linux User #207535 @ http://linuxcounter.net
Klaus Johannes Rusch
2016-10-28 21:21:51 UTC
Permalink
Post by Zhiliang Hu
Although I used procmail for so long I never figure out what kind of
"script" rules it follows. For example in one of my rc script I try
DISTCOUNT=`grep -cv '^(' dist` -1
procmail: Skipped "-1"
How can I get over this without getting it to external script for a
simple calculation like this?
From procmailrc(5):

The assignments and substitutions of these environment
variables are handled exactly like in sh(1) (that includes
all possible quotes and escapes), with the added bonus
that blanks around the '=' sign are ignored and that, if
an environment variable appears without a trailing '=', it
will be removed from the environment. Any program in
backquotes started by procmail will have the entire mail
at its stdin.


Complete with safeguards against an empty grep result:

sh -c "VAR1=`grep -cv '^(' dist`;let DISCOUNT=${VAR1:-0}-1"
--
Klaus Johannes Rusch
***@atmedia.net
http://klausrusch.atmedia.net/
Ruud H.G. van Tol
2016-10-28 22:03:51 UTC
Permalink
Post by Zhiliang Hu
Although I used procmail for so long I never figure out what kind of
"script" rules it follows. For example in one of my rc script I try to
DISTCOUNT=`grep -cv '^(' dist` -1
procmail: Skipped "-1"
How can I get over this without getting it to external script for a
simple calculation like this?
Let's use a bit of procmail:

test.msg, is a file with some lines of text,
and 18 of them don't start with an X.

test.rc:
# - - - - - - - - - -
TESTCOUNT=`grep -vc '^X' test.msg`
LOG="$TESTCOUNT - 1 = "

:0
*$ $TESTCOUNT^0
* -1^0
{ TESTCOUNT=$= }

LOG="$TESTCOUNT
"
# - - - - - - - - - -


# And then run it:

$ procmail -m test.rc < /dev/null
18 - 1 = 17

-- Greetings, Ruud

Loading...