script broadcast email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script broadcast email
# 1  
Old 07-17-2012
<Solved> script broadcast email

Dear All need advice,

I just want broadcast email with mail from shell script, where the script look up the file that contain email address and password

Code:
#!/bin/bash
SUBJECT="Mailserver Baru"
ISIEMAIL="/tmp/emailmessage.txt"
 for a in `(sed 's/"//g;s/\,.*//g' $1)`;
do
echo > $ISIEMAIL
EMAIL="$a"
echo "Dear $a" >> $ISIEMAIL
{  

for b in `sed 's/"//g;s/^.*\(........\)$/\1/g' $1`;
	do
{
echo; echo >> $ISIEMAIL
	echo "Kami sedang mengupgrade system email server, password email $EMAIL yang baru adalah $b" >> $ISIEMAIL
	echo "Mohon segera mengganti password anda dengan mengakses alamat berikut" >> $ISIEMAIL
     };
done;
echo; echo >> $ISIEMAIL
   };
break;
done;
/usr/bin/mail -s "$SUBJECT" "$EMAIL" < $ISIEMAIL 
echo > $ISIEMAIL

content of $1 ;

"admin@somedomain.com","#97ukjkl"
"agung@mydomain.com","2adfpkjg"

the output after execute command ;

Dear admin@somedomain.com

Kami sedang mengupgrade system email server, password email admin@somedomain.com yang baru adalah #97ukjkl
Mohon segera mengganti password anda dengan mengakses alamat berikut

Kami sedang mengupgrade system email server, password email admin@somedomain.com yang baru adalah 2adfpkjg
Mohon segera mengganti password anda dengan mengakses alamat berikut

$a = wrong, because just read admin@somedomain.com
$b = right, because read on password field from each line

myquestion is ;

how can i use this script correctly, i mean execute line by line and looping till done

need your advice

Last edited by survive; 07-18-2012 at 08:09 AM.. Reason: Solved
# 2  
Old 07-17-2012
Useless Use of Backticks

You should read the lines once, process once, instead of reading them n times and processing them once.

If you're running sed to process a single line, you're probably doing something wrong. Use shell builtins for it instead.

Also, you can use a little-known trick of xargs to process the quotes for you.

Code:
$ cat parse.sh

# Remove quotation marks via xargs trick -- xargs parses quoted strings
xargs -n 1 < data > /tmp/$$

while IFS="," read A B
do
        echo "A is $A"
        echo "B is $B"
done < /tmp/$$

rm -f /tmp/$$

$ ./parse.sh

A is admin@somedomain.com
B is #97ukjkl
A is agung@mydomain.com
B is 2adfpkjg

$

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-18-2012
thank's you sir,
it's work like charm,
here the code ;

Code:
#!/bin/bash
SUBJECT="Mailserver Baru"
ISIEMAIL="/tmp/emailmessage.txt"
xargs -n 1 < $1 > /tmp/$$

while IFS="," read A B
do
#        echo "A is $A"
#        echo "B is $B"
echo > $ISIEMAIL
EMAIL="$A"
echo "Dear $A" >> $ISIEMAIL
echo; echo >> $ISIEMAIL
        echo "Kami sedang mengupgrade system email server, password email $A yang baru adalah $B" >> $ISIEMAIL
        echo "Mohon segera mengganti password anda dengan mengakses alamat berikut" >> $ISIEMAIL
echo; echo >> $ISIEMAIL

/usr/bin/mail -s "$SUBJECT" "$EMAIL" < $ISIEMAIL
#echo > $ISIEMAIL 
done < /tmp/$$
rm -f /tmp/$$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Broadcast on AIX

hello how to disable brodcast from AIX 5.3 ? user get on workstation massage from root thx (3 Replies)
Discussion started by: ariec
3 Replies

2. Programming

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (6 Replies)
Discussion started by: moti12
6 Replies

3. IP Networking

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (0 Replies)
Discussion started by: moti12
0 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. Shell Programming and Scripting

Shell script to give broadcast and network address

Hello, I am running a post script in autoyast where I am trying to set the broadcast and network address. I have the ip address and netmask already (reading from a file).. I saw the post from fpmurphy but it is using ksh which isn't an option in autoyast. Thanks in advance! (3 Replies)
Discussion started by: bloodclot
3 Replies

6. Programming

How to broadcast a message ?

My problem definition is ,I have to send a message from one node in a network and it has to be broadcasted to all other nodes in the network.The program what I have given below will be running in all the nodes in the network.The same program should be capable of sending(broadcasting) and receiving.... (0 Replies)
Discussion started by: vigneshinbox
0 Replies

7. UNIX Desktop Questions & Answers

broadcast

Can anybody hellp me troubleshoot this error. Using HP-Uxix B.10.X " *****ARPA/9000 NETWORKING***** Mon Jun 30 SAT 2003 20:18:12.xxxxxxx DISASTER Subsys: NS_LS_PROBE LOC:01001 Network NS_LS_PROBE DISASTER 1001, pid arp: ether address is broadcast for IP address zzzzzzz! " where... (1 Reply)
Discussion started by: SEB
1 Replies

8. Shell Programming and Scripting

shell script queries: $home; broadcast ping

Dear all, This is the Bionic Fysh again. I have two quick questions: 1- when writing shell scripts, how does one allow the tilda ~ into the script ? e.g ls ~; ls ~me; user=you; ls ~$user (N.B I think that for this one you need: ls `~$user`) 2- In FreeBSD 4.0, I would like for a... (6 Replies)
Discussion started by: bionicfysh
6 Replies

9. UNIX for Dummies Questions & Answers

broadcast email???

Hi all, How can i send email to all the users on a box? Thank you all (1 Reply)
Discussion started by: solvman
1 Replies

10. IP Networking

broadcast address

What is the significance of the broadcast address? (1 Reply)
Discussion started by: 98_1LE
1 Replies
Login or Register to Ask a Question