procmail
[Top] [All Lists]

Re: Forwarding?

1998-10-19 14:51:06
1998-10-20-00:18:09 era eriksson:
 >> tmp=/tmp/`basename $0`.$$; trap "rm -rf $tmp" 0

What's the purpose of using a directory?

Well, two; it's simpler to set up and to clean up when (as in this case) I
want multiple tmp files. And in many settings the sequence

        umask 077; mkdir $tmp || die

is atomic and secure against a great many potential race conditions. Possibly
not all, though.

Shouldn't there be a trap for when the script is ctrl-c:ed or hupped in the
middle, too?

I dunno, are you planning on sending a SIGINT or HUP at your automatic mailing
list forwarding process, and if so do you want it to silently clean up and
exit? If all of those are true then by all means include some other numbers
after the "0" at then end of the "trap".

Are you sure this is necessary? (If yes, why not store the script in a
here document? Anything to avoid an explicit temp file :-)

Go for it. Get quoting right so the xargs will be reading from the address
list on stdin, but the mail processes it fires off will be reading from the
message text. Also try to make sure you get the quoting right so you don't
have to worry about funny content in the message body. After thinking about it
for only a couple of minutes the two-tmp-file seemed simplest to me; if you
find a simpler way to do it I'd certainly love to hear about it:-).

#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
umask 077
TMP=/tmp/helper-script.$$
trap 'rm -f $TMP; exit 1' 1 2 3 15
cat >$TMP
while read address; do
    /usr/lib/sendmail -oi "$address" <$TMP
done <addrss.txt
rm -f $TMP

Yeah, it won't send to multiple recipients, but like we have been
saying, you should be using a real mailing list manager if you want it
to be nice and pretty (on the outside :-)

If you have enough addresses that the far simpler

        ! `cat addrss.txt`

which is roughly

        |sendmail `cat addrs.txt`

blows up, then your loop will be invoking the sendmail some thousands of times
more often than mine. Good idea? Let's call it a matter of taste. I wouldn't
do it.

BTW, I have a web page about the ARG_MAX issue which might clarify the
original question. <http://www.iki.fi/~era/unix/arg_max.html>

Just tried visiting that page, got "404 File Not Found".

You could of course make the script read more than one address at a
time. For the truly desperate, here's a one-liner which takes a file
of one address per line and spits out 25 at a time:

  sed -e 'N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;s/\n/ /g'

It's not really obvious to me how this is preferable to xargs. If you are
absolutely determined to replace the extra helper script with a while read
args loop, then why not use fmt to build up wide lines? It uses a line length
limit rather than word counts, which is probably a better fit for OS
limitations anyway.

-Bennett

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