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".