procmail
[Top] [All Lists]

Re: "wc" in pipe not working!

1997-01-15 15:15:43
doctor-w(_at_)usa(_dot_)net asked,

| The buggy line is the "wc" one, where it SHOULD return a line count...  In
| the shell it does OK...  In the .rc file, it doesn't...  It returns a NULL
| string.

| :0 c
| * ^Subject:.*Welcome to the chat list
| * ^From:(_dot_)*Request(_at_)xxx(_dot_)Com
| | (   echo "Errors-To: Doctor(_at_)Netcom(_dot_)Com" ; \
|       echo "Reply-To: Chat(_at_)xxx(_dot_)Com" ; \
|       echo "X-Loop: Doctor(_at_)Netcom(_dot_)Com" ; \
|       echo "X-List: Chat (Announcement)" ; \
|       echo "To: Multiple Recipients of Chat List <Chat(_at_)xxxCom>" ; \
|       echo "Subject: [Chat] Please welcome $TO2 to the list!" ; \
|       echo "From: MReply List Server <Chat(_at_)xxx(_dot_)Com>" ; \
|       echo "X-Commands-To: Request(_at_)xxx(_dot_)Com - commands in body" ; \
|       echo "" ; \
|       echo "Please welcome" ; \
|       echo "$TO2" ; \
|       echo "as a new member to our list!" ; \
|       echo "" ; \
|       /usr/bin/echo -n "There is a total of:" ; \
| >>>   ( /usr/ucb/wc -l ~/sr/sr-chat | cut -c1-8 ) ; \
|       echo "current subscribers now on our list!" ; \
|       ) \
|       | msend -q $HOME/lists/chat

As Tim and Irena have explained, the Doctor's $SHELL setting -- this action
line is thick with characters from $SHELLMETAS, so procmail is calling a
shell to handle it -- probably is one that doesn't understand tildes.  Using
the $HOME variable would be better:

        ( /usr/ucb/wc -l $HOME/sr/sr-chat | cut -c1-8 ) ; \

It's a good habit not to use tildes in procmailrc files, because if the
action line contains no characters from $SHELLMETAS (or it's a simple
save-to-folder), procmail itself cannot grok tildes.  So even if your
$SHELL setting is one that does tilde interpretation when procmail hands
the line over to the shell, it's not a good habit.

I have two more suggestions:

First, that action line does not read in text from the message, so the recipe
needs an `i' flag to tell procmail to ignore write errors.

Second, it is unnecessary to pipe wc to cut.  If wc reads stdin instead of
a file, it won't spit out a filename (it won't even know a filename):

      /usr/ucb/wc -l < $HOME/sr/sr-chat ; \

Third, well, it's a little redundant to say both "current" and "now,"
don't you think?  But maybe this is for a fun-with-pleonasms list and that's
intentional.

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