Mailx recipient from mysql database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mailx recipient from mysql database
# 8  
Old 04-04-2013
Yes, but we need more modifications. I dont have a mysql setup right now. So can you paste the output of
Code:
mysql -uroot -pabcde smsd -N -s -r -e SELECT email FROM recipient

We basically want to remove the header and new line from the sql ouput.

--ahamed

---------- Post updated at 01:44 AM ---------- Previous update was at 01:42 AM ----------

Also, please check the double quotes at the end after EMAIL_ADDRESS.

--ahamed
# 9  
Old 04-04-2013
yes, you're right. we need to remove the new line :-D

i do this:

Code:
mysql -uroot -pabcde smsd -N -s -r -e "SELECT email FROM recipient"

output:
Code:
supervisor@gmail.com
marketing@gmail.com

# 10  
Old 04-04-2013
Try this and if you still get any errors, please paste the output with -x option
Code:
EMAIL_ADDRESS=$( mysql -uroot -pgurlia001 smsd -N -s -r -e "SELECT email FROM recipient" | tr '\n' ' ')

--ahamed
# 11  
Old 04-04-2013
change script to:

Code:
SUBJECT="TEST"
EMAIL_ADDRESS=$( mysql -uroot -pgurlia001 smsd -N -s -r -e "SELECT email FROM recipient" | tr '\n' ' ')
mysql -uroot -pgurlia001 smsd -e "SELECT ID, SenderName, Body FROM inbox" | mailx -s "$SUBJECT" -a From:sales@acme.com "$EMAIL_ADDRESS”


now in one line but with error, output:

Code:
+ SUBJECT=TEST
+ mysql -uroot -pgurlia001 smsd -N -s -r -e SELECT email FROM recipient
+ tr \n  
+ EMAIL_ADDRESS=supervisor@gmail.com marketing@gmail.com  
daemon_emailer.sh: 15: Syntax error: Unterminated quoted string

# 12  
Old 04-04-2013
Code:
EMAIL_ADDRESS="$( mysql -uroot -pgurlia001 smsd -N -s -r -e "SELECT email FROM recipient" | tr '\n' ' ')"

--ahamed

---------- Post updated at 02:17 AM ---------- Previous update was at 02:15 AM ----------

Sorry, updated the code. Please try this.

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 13  
Old 04-04-2013
already changed the script with:

Code:
SUBJECT="TEST"
EMAIL_ADDRESS="$( mysql -uroot -pgurlia001 smsd -N -s -r -e "SELECT email FROM recipient" | tr '\n' ' ')"
mysql -uroot -pgurlia001 smsd -e "SELECT ID, SenderName, Body FROM inbox" | mailx -s "$SUBJECT" -a From:sales@acme.com "$EMAIL_ADDRESS”

output:

Code:
+ SUBJECT=TEST
+ tr \n  
+ mysql -uroot -pgurlia001 smsd -N -s -r -e SELECT email FROM recipient
+ EMAIL_ADDRESS=supervisor@gmail.com marketing@gmail.com 
daemon_emailer.sh: 15: Syntax error: Unterminated quoted string

# 14  
Old 04-04-2013
Did you notice the double quote in the last statement(...|mailx..) i.e. after $EMAIL_ADDRESS? is it a copy paste error or is there something wrong in the script itself?

--ahamed
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Web Development

Apache users from MySQL database

Hi team, How can I implement a users in MySQL database for Apache users, assuming that I'm using RHEL6. That is to say, how can I design this database and how let's Apache server know those user in this database. Thanks in advance.. (3 Replies)
Discussion started by: leo_ultra_leo
3 Replies

2. Programming

Mailx recipient from mysql database

Dear All, Can I make Mailx to read recipient address from a mysql database? I already tried emailing with bash script: SUBJECT="TEST" export EMAIL_ADDRESS=`mysql -uroot -pabcde smsd -e "SELECT email FROM recipient"` mysql -uroot -pabcde smsd -e "SELECT ID, SenderName, Body FROM inbox" |... (2 Replies)
Discussion started by: jazzyzha
2 Replies

3. Shell Programming and Scripting

How to backup a particular Database in MYSQL?

Hi All, Thanks in Advance!! How to backup a particular Databases..through Bash script!! For example i have 6 databases; Anish linux Software Questions Rhce Google these are the databases i have from that i want to take "Anish" and "questions" database backup regularly.... (4 Replies)
Discussion started by: anishkumarv
4 Replies

4. UNIX for Dummies Questions & Answers

Connect MySQL database from Unix

How to connect a MySQL database from unix using unix shell scripting ( people are using perl scrpt to connect the same database). I want to access a MySQL database through a shell script (4 Replies)
Discussion started by: apsprabhu
4 Replies

5. Shell Programming and Scripting

Mailx Recipient and Name Script

Hi To All, I have a file with email addresses, most of which have names associated with them, it looks like this: http://img230.imageshack.us/img230/8255/94731317.th.jpg I am trying to come up with a script to use mailx (or anything else really) to send an email to... (4 Replies)
Discussion started by: slicker
4 Replies

6. UNIX for Dummies Questions & Answers

mailx recipient restriction

maybe a simple question, but i've looked around and not been able to find anything. is there a restriction on how many recipients can be used in a single mailx command? whether it's a numeric restriction or a size restriction (like 256k for the whole recipient parameter). thanks a lot. (6 Replies)
Discussion started by: chris32680
6 Replies
Login or Register to Ask a Question