Echo - Sending mail to multiple addresses

Hi,

If I want my script to send a mail to multiple recipients I can do the following:

if [ `echo $err_string1 | wc -c` -gt 1 ]
then
echo $err_string1 | mailx -s "UAT CPU ALERT" 1@email.com
echo $err_string1 | mailx -s "UAT CPU ALERT" 2@email.com
fi

Can this also be done something like:

if [ `echo $err_string1 | wc -c` -gt 1 ]
then
echo $err_string1 | mailx -s "UAT CPU ALERT" 1@email.com; 2@email.com
fi

Yes to alternative 1.

No to alternative 2.

Most implementations of "mailx" only accept one recipient address.
That address could of course be a mailing list.

In unix the semi-colon character separates two commands on the same line. For some reason, Microsoft proprietary email software uses a semi-colon to delimit a list of email addresses whereas the rest of the industry uses a comma.

It is possible to present the mail recipient with a list of recipent addresses and CC addresses by using "mailx" "tilde" commands. You still need one "mailx" command per recipient.

1 Like