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 to
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 like
"/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 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.
umask 077; mkdir $tmp || exit 1
Two more commands. Set the umask to 077; this means that files and directories
we create won't be accessible to other users --- strips off group and world
read/write/execute permissions as things are created. Then create the tmp
directory, and if the mkdir fails exit immediately with error status.
Copy stdin (the message that procmail is feeding to this helper script) to a
file named "message" in the tmp directory.
(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
/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
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 against
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 hooked up
to the list of arguments (addresses), which makes it tricky to hook up the
stdin of the mail-sending program to some other data file.