linux - Redirection of MySQL Queries into a log/text file in shell script and read the file for particular string -



have written shell script mysql_test.sh connect mysql database linux shell , execute 3 different select statements following,

select count(*) my_column_name <table_name> <condition>

shell script looks following.

mysql -u$master_db_user -p$master_db_passwd -p$master_db_port -h$master_db_host <<eof $bs_query  $exp_query $roi_query eof 

now requirements are,
1. redirect output of 3 above queries single text or log file.
2. send email if of query returns > 0 rows.
3. attach text/log file while sending email.

please me in fixing 1 , 2. in advance.

mysql -u$db_user -p$passwd -p$db_port -h$db_host <<eof > output.txt $bs_query  $exp_query $roi_query eof  # each line (i.e. containing count(*) result), test if count(*) != 0 line_number=1 line in `cat output.txt`;   if [ $((line_number % 2)) -eq 0 ];     if [ $line -ne 0 ];       `( echo "here report"; uuencode output.txt output.txt ) | mail -s "sql report" admin@sqldb`       exit     fi   fi   line_number=$((line_number + 1)) done 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -