I am trying to write a Bash script to run a MySQL query from a string constructed in the script. I have been able to construct the query string, and it looks correct when echo'd. And I can cut and paste it into the shell command line and it runs. But, I need to basically cut the query results to just the words, OK or CRITICAL. Nothing else. When I try to save the query result to a bash variable I get:
mysql: unknown option '-2'
If I cut out the grep and cut code, I get the mysql --help results. So, it's not liking my mysql string, but I don't know why. Help?
BTW- Running CentOS 6.3
alert=`mysql myDB -e "select value from config_table where name=\"ach_alert_time\"\G" | /bin/grep value: | /bin/cut -f2 -d:`
echo $alert #Brings back 18,50,00
sql="mysql myDB -e 'select if(count(*) > 0,\"CRITICAL\",\"OK\") as STATUS from xyz_batch where timestamp > concat(date(now()),\" \",maketime("$alert"))\G' | /bin/grep OK | /bin/cut -f2 -d:"
echo $sql # mysql myDB -e 'select if(count(*) > 0,"CRITICAL","OK") as STATUS from xyz_batch where timestamp > concat(date(now())," ",maketime( 18,50,00))\G' | /bin/grep OK | /bin/cut -f2 -d
status=`$sql`
# Whoops!
# mysql: unknown option '-2'
echo $status