Register
It is currently Thu Jul 24, 2014 6:19 am

script to query mysql and send email


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Thu Jul 08, 2010 9:31 pm   

Joined: Thu Jul 08, 2010 9:29 pm
Posts: 1
Hi i need a script that queries a particular MYSQL table and emails the contents off particular fields.


Top
 Profile  
 PostPosted: Thu Jul 08, 2010 11:44 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
Code:
mail -s'subject' name@machine.dom <<EOF
mysql -h"$Host" -D"$Base" -u"$User" -p"$Passwd" -Ne 'mysql statement'
EOF


Top
 Profile  
 PostPosted: Fri Jul 09, 2010 1:17 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Watael wrote:
Code:
mail -s'subject' name@machine.dom <<EOF
mysql -h"$Host" -D"$Base" -u"$User" -p"$Passwd" -Ne 'mysql statement'
EOF

That would email the litteral mysql command with all it's arguments and not the output. I would suggest the following

Code:
mysql -u $user -p $password -h $host $dbname -e 'sql-statement' | mail -s "$subject" email@address


Top
 Profile  
 PostPosted: Fri Jul 09, 2010 1:52 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
indeed. I forgot command substitution:
Code:
mail -s'subject' name@machine.dom <<EOF
$(mysql -h"$Host" -D"$Base" -u"$User" -p"$Passwd" -Ne 'mysql statement')
EOF


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP