Mail from a shell script?

Ryan Sommers ryans at gamersimpact.com
Mon Sep 13 10:25:36 PDT 2004


I'm attempting to have a few shell scripts email output. I'm running into
a few problems and was wondering if there were any ways to overcome them
in a shell script or whether I'll have to go to perl or not. (Note, shell
doesn't matter, I've been using sh but recently went to bash since sh on
solaris (one of the machines the scripts get used on) doesn't support the
-e expression for test(1)).

First problem I ran into. I'm attempting to send the mail via `which
mail`. I first was going to attempt to concatenate the message via
"message=${message}$'\n'<other line>" However, this strips the newlines
out of the variable (both sh and bash). I then tried using the <<string
redirection in bash/sh and same thing happened.

My next thought was to open an fd through which to pipe output since the
shells support it. However, it seems they only support opening a file for
read/write, not a pipe.

So, my ultimate question is, is there any way to send an email from a
shell script without creating a "wrapper script" that pipes the output of
one script into the mail program. Ie script1 contains only "script2 | mail
<recip>".

Ryan
ryans at gamersimpact.com


More information about the freebsd-questions mailing list