procmail
[Top] [All Lists]

Re: Forwarding?

1998-10-15 14:55:22
1998-10-15-14:55:57 Eric, Audet:
[...] somewhere in the faq it says:

:0
* condition
! `cat addrss.txt`

This will break as soon as the output  of the backsticks is too large
for your shell to handle.

What is the backsticks ... anyway around it?

Backticks --- `` --- are shell syntax; they tell the shell to run the command
within them (in this case, "cat addrss.txt", which prints the contents of the
file "addrss.txt" to stdout), and captures its stdout, and substitutes it as
command-line arguments (flattening it into one long line by replacing newlines
with spaces). The comment about breaking comes up because some shells, and
some Unix kernels, have limits on the length of a possible command-line. If
the list of addresses grows to be too long for your system's limits, then you
have to break up the list and run multiple commands with shorter lists. The
standard solution to this is xargs, but that can't be trivially done here,
since the first invocation would ``consume'' the message, and it wouldn't be
around any more for the remaining mail sends. So you've got to explicitly set
up a temp file. There's undoubtedly some fine way to do this within procmail,
but I'm frankly not a procmailrc wiz, so I'd dodge the problem by creating a
helper script to do the mass mailing; if I called the helper script
"helper-script" then the procmail recipe might read

        :0
        * condition
        | helper-script

or, if helper-script isn't on your PATH, a fully-qualified name like

        :0
        * condition
        | $HOME/bin/helper-script

Now helper-script could read something like

    #!/bin/sh
    tmp=/tmp/`basename $0`.$$; trap "rm -rf $tmp" 0
    umask 077; mkdir $tmp || exit 1
    cat >$tmp/message
    (echo '#!/bin/sh';echo '/usr/lib/sendmail "$@" <'$tmp/message) >$tmp/sender
    chmod 755 $tmp/sender
    xargs $tmp/sender <addrss.txt

There's lots of ways to do it; that's just the first that leaps to mind. But
that's not terribly efficient, nor terribly safe; if you are dealing with a
big enough mailing list to break shell backtick expansion, then you probably
ought to be using a serious mailing list manager. These include ezmlm,
smartlist, majordomo, and I'm sure many many others.

-Bennett

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