tags:

views:

23

answers:

3

Maybe i should use python or perl but i dont know any.

I have 4 statements and i would like to check if there are any errors longer then an hour. My user is setup so i dont need to enter a mysql user/pass. This statement is in mysql_webapp_error_check.sh

#!/bin/bash
mysql testdb -e "select count(*) from tbl where last_error_date < DATE_SUB(NOW(), INTERVAL 1  HOUR);"

How do i make it give me the return value (count(*)) instead of printing to screen?

Then i'll write an if statement and output to stdout/err for cron to use to email me (otherwise i want the script to be silent so nothing is emailed unless theres a problem)

+1  A: 
#!/bin/bash
echo show databases\; | mysql -u root | (while read x; do
  echo "$x"
  y="$x"
done
echo "$y"
)
DigitalRoss
A: 

I usually do this:

 var=`mysql -e "SELECT COUNT(*) FROM ...\G" | awk '/COUNT/{print $2}/'`
Wrikken
A: 

in bash, you use $() syntax.

#!/bin/bash
ret=$(mysql testdb -e "select count(*) from tbl where last_error_date < DATE_SUB(NOW(), INTERVAL 1  HOUR);")
if [[ "$ret" > 0 ]];then
   echo "there is count"
else
   echo "no count"
fi
ghostdog74
It doesnt work. It always says there is count. I tested with -e "select 0;" and the actual command i'll be using. Both are 0 and reported nonzero
acidzombie24