[Gllug] pipe data to mail body

Richard Cohen richard at vmlinuz.org
Fri Feb 27 16:38:08 UTC 2004

On Fri, 27 Feb 2004, ben f wrote:

> > You can run the various things you want concatenated
> > in a subshell, then
> > send the output from that subshell to mail, like
> > this:
> > -----
> > (echo Subject: stuff
> > echo
> > head -1 $log | awk '{print $1}'
> > awk -f ~/sh/myextract.awk $log
> > cat ~/.sig ) | mail -s 'test' root
> > -----
> Rich,
> This was just the sort of construct I needed - thanks.

Pleasure :-)

> Couple of things:
> 1. Did you mean to put an echo in front of the "("
> starting the subshell to feed it through the pipe?
> I had to do this!

No, I didn't - and I don't think you should have to either.  I've just
tested it specifically with mail, on my work Solaris box, under bash, and I
don't need the echo.  I only put the echos in to include either a blank line
(between the header(s) and the body) or literal strings...

> 2. One side-effect is that the shell eats my newlines.
> Is there a way to prevent the shell doing this?

I'm not sure what you mean by this...  You are using bash, I assume?  The
mail you get/send should look just like what you get if you send the output
from each of the commands to a file, using append (>>).

> Thanks,
> Ben

Gllug mailing list  -  Gllug at gllug.org.uk

More information about the GLLUG mailing list