Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-10-2009, 09:52 AM   #1
LQ Newbie
Registered: Apr 2009
Posts: 9

Rep: Reputation: 0
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...

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

This is part of my script:

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

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


Old 06-10-2009, 11:11 AM   #2
Registered: Aug 2005
Posts: 298

Rep: Reputation: 30
in my2.sql put

$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

cid=$(awk '{ print $2 }' /home/test.txt | sed -n 2p)
echo "cid is" $cid
. /home/my2.sql
echo $query | /home/build/env/util/ biller > /home/test2.txt
cat /home/test2.txt
Maybe something along those lines will work


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing awk output to $variable for shell script? NewnanNOC Programming 3 10-23-2008 02:08 PM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 08:01 AM
Possible to call a shell script within a mysql query? zhjim Linux - Server 2 08-30-2007 02:23 AM
passing a shell variable into awk - syntax for correct interpretation? johnpaulodonnell Programming 3 06-19-2007 12:13 PM
Passing a variable to a cgi script WindowBreaker Slackware 1 04-03-2006 10:02 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration