Solved

How to include email addresses within a file and then send a message by using that file in the Unix bash shell script?

Posted on 2012-04-12
2
563 Views
Last Modified: 2012-04-12
In the Unix bash script, how can I create a file with some email addresses and then use that file to send messages through Unix bash shell script?

For example, I would like to send my message to: person1@yahoo.com, person2@yahoo.com, and person3@yahoo.com  

How above email addresses need to be entered in the file "mailfile.txt" and what would be a command to send "mailfile.txt" in the Unix bash shell script?

I tied to enter email addresses in the "mailfile.txt" the following way:
person1@yahoo.com, person2@yahoo.com, person3@yahoo.com

then I tried to run below sript:

mailSubject="ERROR: Module10 - FAILED, REVIEW Program LOG"
mydir=/year/month/week/day
mymail=$mydir/mailfile.txt

     (echo "----------------------------------------------------------------"
      echo "Module10 Update Program"
      echo "ERR Msg: Module10 failed review program LOG"
      echo "----------------------------------------------------------------") | mailx -s $mailSubject $mymail

Open in new window

No errors are produced and no mail has been send to those three recipients.
0
Comment
Question by:labradorchik
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 37838887
(echo "----------------------------------------------------------------"
      echo "Module10 Update Program"
      echo "ERR Msg: Module10 failed review program LOG"
      echo "----------------------------------------------------------------") | mailx -s $mailSubject $(cat $mymail)

My suggestion will also work if the file contains a single address per line.
0
 

Author Comment

by:labradorchik
ID: 37839199
Script works great!! Thank you!!! :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Utilizing an array to gracefully append to a list of EmailAddresses
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question