What a good guy YOU ARE!
Last small question ... BTW it was clear :)
What will happen if the message has an attachement? (I guess I could try
it) But is this program really forward the exact message to the list of
From: 'Bennett Todd' [mailto:bet(_at_)mordor(_dot_)net]
Sent: Friday, October 16, 1998 9:33 AM
To: Eric, Audet
Subject: Re: Forwarding?
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
I'll explain it; I'm fluent in perl, but it would take so much more perl
say this that I'd rather just explain the shell code:-).
What I can see is that you use sendmail sending to all addrss ... but
what is the $(_at_)? the message?
Saved in a tmp file, named $tmp/message.
Now for a line-by-line explanation of the shell script.
Standard, tell the OS that this is a shell script.
tmp=/tmp/`basename $0`.$$; trap "rm -rf $tmp" 0
Two commands. First, set the internal shell variable "tmp" to something
"/tmp/helper-script.948"; we built it up from "/tmp/", the output of the
basename command run on argv (to strip off any leading directory path
the command name), and "$$" which shell expands into the PID of the
shell process. The second command "trap" sets an on-exit hook (that's
trap for larger numbers sets signal handlers). This will delete the tmp
directory on exit.
umask 077; mkdir $tmp || exit 1
Two more commands. Set the umask to 077; this means that files and
we create won't be accessible to other users --- strips off group and
read/write/execute permissions as things are created. Then create the
directory, and if the mkdir fails exit immediately with error status.
Copy stdin (the message that procmail is feeding to this helper script)
file named "message" in the tmp directory.
(echo '#!/bin/sh';echo '/usr/lib/sendmail "$@" <'$tmp/message)
Create a second tmp file, which is a shell script to invoke sendmail
stding redirected from the message; after executing this command there
a script named something like "/tmp/helper-script.948/sender",
/usr/lib/sendmail "$@" </tmp/helper-script.948.message
Such a script, when invoked, will send a copy of the message (that was
using the "cat" command above) to all the recipients listed on its
chmod 755 $tmp/sender
Turn on execute permission bits for this sender script.
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
shell or OS command-line length limits.
The reason I ended up going with the moderately convoluted
helper-script-calling-helper-script is that xargs wants _its_ stdin
to the list of arguments (addresses), which makes it tricky to hook up
stdin of the mail-sending program to some other data file.