[Gllug] pipe data to mail body

Richard Cohen richard at vmlinuz.org
Fri Feb 27 16:02:52 UTC 2004

On Fri, 27 Feb 2004, ben f wrote:

> Hi everyone,
> quick query:
> I want to receive an e-mail that has several outputs
> in it. e.g.
> awk -f ~/sh/myextract.awk $log | mail -s 'test' root
> So the output of the awk script gets sent as the mail
> body. But (!), I also want other outputs to go into
> it, such as:
> head -1 $log | awk '{print $1}'
> One idea is to use <<EOF and put my other stuff
> in variables but I don't like that.
> Is there a neat way I can achieve this without
> resorting to putting it all in a buffer file and then
> sending that file? I'm just curious as at the moment
> the extent of my knowlege makes that my preferred
> option.

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
head -1 $log | awk '{print $1}'
awk -f ~/sh/myextract.awk $log
cat ~/.sig ) | mail -s 'test' root

> Thanks,
> Ben

Gllug mailing list  -  Gllug at gllug.org.uk

More information about the GLLUG mailing list