Creating a multi-recipient email script

Well, I'm fairly new to shell scripting, so please excuse my newbieness :slight_smile:

I was wondering if it was possible to create a shell script that retrieves a list of recipients in a list_file and sends a message out all at once?

An example of a list file would look similar to this:

$ cat data/list_file
user1@host_xyz nickname1
user2@host_abc nickname2
..... ......
userN@host_N nicknameN

As for the message file being emailed, I would LOVE to have it personalized in this fashion for my site:

To {NICKNAME}:

We appreciate your registration to the RSG board. Here are you authorization credentials:

username: {EMAIL}
password: {PASSWORD}

Your RSG account will expire on: {EXPIRATION_DATE}

Cheers,

System Admin

Now, I've only been playing around with shell scripts for a few days, but I know I can use "mkpasswd" to create a password for the user and "date" to calculate the expiration date (which is exactly one year after the email is sent). I'm also assuming that I can use "sed" to substitute the correct fields, correct?

Well, I really don't know how to begin on this. I think it would be great for my site if I can implement something like this. I'd much rather stick to this shell scripting idea since I haven't really touched on it before.

If anyone has some code I can look at or tips to give me, I would greatly appreciate it.

Here's an update. This is what I've written so far and I'm getting a whole bunch of errors:

#!/bin/sh
#usage mailscript msg_file  list_file  "subject"

MAILTEXT=$1
INFILE=$2
SUBJECT=$3

exec 0<${INFILE}
while read EMAIL NICKNAME
do

PASS=`/usr/linux/bin/mkpasswd`
EXDATE=`/usr/linux/date --date 'next year' +%F`

 sed -e "s/{NICKNAME}/$NICKNAME/g" -e "s/{EMAIL}/$EMAIL/g" -e 
"s/{PASSWORD}/$PASS" -e "s/{EXPIRATION_DATE}/$EXDATE" $MAILTEXT | mailx -s 
"$SUBJECT" $ADD

done

exit

#End of script

Since I've only been playing around with scripts for a few days, I have no idea what I'm doing wrong. It seems right to me, but it's not working. If anyone can help me out I'd greatly appreciate it.

I use ksh, not sh...

I assume that the only two fields in list_file are EMAIL and NICKNAME. Instead of

exec 0<${INFILE}
while read EMAIL NICKNAME
do

you could try using

cat $INFILE |
while read EMAIL NICKNAME
do

Even though it looks like your sed command would work for me (in ksh), it may not work in sh. Did you create that sed command from an example you found somewhere?