LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-30-2004, 07:32 PM   #1
zaubara
LQ Newbie
 
Registered: Apr 2003
Posts: 27

Rep: Reputation: 15
MySQL in a shell script?!


Hey guys!
Im in charge to code a shell script that checks a mySQL DB for email adresses and sends a predefined email to the ones returned...
Sooo ... is it even possible to have SELECTs in a shell script? And how can I send "real emails" (i mean, through a SMTP server) to those ppl?

Would be great if someone could help me out
Huge thanks in advance,
zaubara
 
Old 05-31-2004, 05:47 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Sure that's possible. Assuming you have a .my.cnf in the home directory of the user that will execute the script. This to make sure the script won't ask for a password, and also there's no password inside the script. Also make sure the file has the proper rights so only root and the user can read the script:
Code:
shell$ ls -l ~/.my.cnf
-rw------- 1 zaubara zaubara    41 Nov 12 2003 /home/zaubara/.my.cnf

shell$ cat ~/.my.cnf
[client]
user=zaubara
password=secretword
Now you can make a shell-script like this:
Code:
#!/bin/bash
QUERY="select email from mailtable"
echo "$QUERY" | mysql yourdatabase | while read address ; do
    cat filewithmessage.txt | mailx -s "some subject" "$address"
done
Notes:
- For sending mail this way, you need to have a MTA (mailserver, e.g. sendmail) running on the system
- If you don't have the "mailx" program, try "mail".

Last edited by Hko; 05-31-2004 at 05:50 AM.
 
Old 05-31-2004, 05:27 PM   #3
zaubara
LQ Newbie
 
Registered: Apr 2003
Posts: 27

Original Poster
Rep: Reputation: 15
Wow, great! You really helped me out thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
PHP Shell Script (with MySql) Tony Empire Programming 1 09-20-2005 09:59 AM
MySQL connection in shell script - how to? philipz Programming 3 04-29-2004 07:04 PM
Import records to MySQL Database from a shell script chrisk5527 Linux - General 12 03-24-2004 09:49 PM
How get a mysql shell response in a script. philipina Programming 3 03-16-2004 11:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration