Operating System - HP-UX
1748185 Members
4187 Online
108759 Solutions
New Discussion юеВ

Re: MAILX oneliner to more than one addressee

 
SOLVED
Go to solution
Andrew Crozier
New Member

MAILX oneliner to more than one addressee

Hi within a script I have the requirement to send a mail to more than one user

cat $file2 |mailx -s "sMail Subject" UnixTeam@ANother.com first.name@ANother.com second.name@ANother.com third.name@ANother.com

the command works fine from the prompt or within the script (when only one mail address is used) however what is the correct syntax to use within a script as no mails are sent at all not even to the first recipient?
6 REPLIES 6
Steven E. Protter
Exalted Contributor
Solution

Re: MAILX oneliner to more than one addressee

Shalom,

Separate the addresses with commas

echo "steve was here" |mailx -s "sMail Subject" invest,root


echo "steve was here" |mailx -s "sMail Subject" invest@yourdoman.com,root@yourdomain.com

Check /var/adm/syslog/syslog.log for delivery success.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Andrew Crozier
New Member

Re: MAILX oneliner to more than one addressee

Initial tests look very promising many thanks for the quick response & useful information.
Mel Burslan
Honored Contributor

Re: MAILX oneliner to more than one addressee

Andrew,

as you can guess, the command line has a limited length and you might not be able to fit all the recipients to a single line. In which case you either set up an environment variable (again with the limitations, like

maillist="user1@domain.com,user2@domain.com,..."
mailx -s "subject here" $maillist

or you can edit the /etc/mail/aliases file and create an alias mail list, entering email addresses over there, like this:

user1 : someone@domain.com
user2 : someone.else@another domain.com
user3 : stranger@strangeplace.com
hpuxadm : user1,user2,user3

save and exit

then

mailx -s "subject here" hpuxadm

Hope this helps
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor

Re: MAILX oneliner to more than one addressee

sorry.. skipped step here if you are using aliases file. After you edit, save it and exit, you need to run command

newaliases

to compile the aliases file into the database form that sendmail/mailx understands.
________________________________
UNIX because I majored in cryptology...
Andrew Crozier
New Member

Re: MAILX oneliner to more than one addressee

many thanks for the useful replies - problem resolved using the `,` to delimit addresses. Helpful point about newaliases also explained failure of earlier attempt to resolve issue.
Dennis Handly
Acclaimed Contributor

Re: MAILX oneliner to more than one addressee

There should be no need to separate the addresses by commas. If it works without them interactively, it should work in a script.

Unless you have a quoting issue:
USERS="abc@def.com def@ghi.com"
mailx -s "test" "$USERS"

This won't work, you have to add those commas or remove the quotes.