procmail
[Top] [All Lists]

Re: Forwarding?

1998-10-19 14:28:26
On Fri, 16 Oct 1998 09:32:56 -0400, "'Bennett Todd'" <bet(_at_)mordor(_dot_)net>
wrote:
1998-10-16-07:49:39 Eric, Audet:
I think I do not understand your script ...If someone could translate
that in perl OR explain me the program
What I can see is that you use sendmail sending to all addrss ... but
what is the $(_at_)? the message?
<...>
tmp=/tmp/`basename $0`.$$; trap "rm -rf $tmp" 0
Two commands. First, set the internal shell variable "tmp" to something like
"/tmp/helper-script.948"; we built it up from "/tmp/", the output of the
basename command run on argv[0] (to strip off any leading directory path from
the command name), and "$$" which shell expands into the PID of the current
shell process. The second command "trap" sets an on-exit hook (that's trap 0;
trap for larger numbers sets signal handlers). This will delete the tmp
directory on exit.

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

(echo '#!/bin/sh';echo '/usr/lib/sendmail "$@" <'$tmp/message) >$tmp/sender
Create a second tmp file, which is a shell script to invoke
sendmail with stding redirected from the message; after executing
this command there will be a script named something like
"/tmp/helper-script.948/sender", containing something like:
     #!/bin/sh
     /usr/lib/sendmail "$@" </tmp/helper-script.948.message
Such a script, when invoked, will send a copy of the message (that was saved
using the "cat" command above) to all the recipients listed on its command
line.

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

xargs $tmp/sender <addrss.txt
Invoke the sender script for all the addresses listed in
addrss.txt, in batches long enough to be pretty efficient, but not
so long as to bang against shell or OS command-line length limits.

Clever, but how about just

#!/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 :-)

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>

/* era */

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'

You have to take out the quotes around "$address" and make sure the
input doesn't contain spaces or other funnies.

-- 
Bot Bait: It shouldn't even matter whether  (`')  Just  (`')  http://www.iki
I am a resident of the State of Washington   \/ Married! \/   .fi/~era/

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