Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-29-2013, 12:45 PM   #1
LQ Newbie
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
Shell script to send multiple recipiants

Need help in a script . Newbie on scripting

I want to send a mail from unix to multiple recepients.
We can do that by using

/opt/csw/bin/mpack -s "test message " <path/file>

Which will send to both recipients listed in the mail as well both address are shown in the mail . I want to create a distribution list and use that list to send to all the recipients and they all should be displayed in a mail .
Old 01-29-2013, 03:51 PM   #2
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,711
Blog Entries: 12

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
I was thinking of two ways, however one applies, but I'll explain.

You can use a loop and open a reference file which has line by line user emails and the loop iteratively calls /opt/csw/mpack with the last argument substituted as you read the reference file.

The one that applies would be that you have a file which has one line, space delimited user emails, no loop and you merely use the entire contents of that file in a single substitution for one call to /opt/csw/mpack. The reason would be so that all recipients would see the full list of other recipients, as you've said here.

A caution is that if that list of recipients becomes really large, it could cause the command to be too long for your shell.
1 members found this post helpful.
Old 01-29-2013, 04:07 PM   #3
LQ Newbie
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled

Thank you rtmistler.

Here is the solution i found

/opt/csw/bin/mpack -s "test message " <path/file> `cat <distributionlist.txt>`

All recipients would see the full list of other recipients

If we dont want that way we can use the for loop sending individually
Old 01-29-2013, 08:33 PM   #4
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,707

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
A better way is to use aliases. A mail alias can be a list of email addresses, then you just send it to the alias name.

It does depend on your mail server to handle aliases.

It is much more efficient as the client mailer only has to deal with one address, and the mail server can batch as many of the recipients together into one connection to a remote server. Also, you can specify the address as a BCC and no one gets to see the list.
Old 01-29-2013, 08:36 PM   #5
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 846

Rep: Reputation: 201Reputation: 201Reputation: 201
Also "mpack" may have a -b option to send in bcc mode. I know that "mailx" does.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to send a mail using shell script gajananh999 Linux - Newbie 2 11-29-2012 01:55 AM
send email to server to start shell script bic Red Hat 5 12-04-2009 09:06 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
write a shell script to send email yenonn Programming 4 02-11-2005 10:06 PM
sendmail won't send from shell or php script dmedici Linux - Software 2 08-24-2004 03:15 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration