LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Passing a variable from shell script to mysql query? (http://www.linuxquestions.org/questions/programming-9/passing-a-variable-from-shell-script-to-mysql-query-731950/)

ne00 06-10-2009 09:52 AM

Passing a variable from shell script to mysql query?
 
I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish...

Code:

. $X='grep foo blah.log'
then 'mysql command SELECT foo FROM bar WHERE ' . $X

or something like that.

This is part of my script:

Code:

cid=$(awk '{ print $2 }' /home/test.txt | sed -n 2p)
echo "cid is" $cid
cat /home/my2.sql | /home/build/env/util/connectdb.sh biller > /home/test2.txt
cat /home/test2.txt

In the my2.sql file:

Code:

select * from Notifications join Events using (EventId) where CustomerId = '&cid';
Any suggestions? Possible? If so what am I doing wrong?

Thanks

David

Four 06-10-2009 11:11 AM

in my2.sql put

Code:

$query = "select * from Notifications join Events using (EventId) where CustomerId = '$cid'";
I don't understand how you want to do this; but from me guessing it might be like so

Code:

cid=$(awk '{ print $2 }' /home/test.txt | sed -n 2p)
echo "cid is" $cid
. /home/my2.sql
echo $query | /home/build/env/util/connectdb.sh biller > /home/test2.txt
cat /home/test2.txt

Maybe something along those lines will work


All times are GMT -5. The time now is 08:28 PM.