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
561 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now