LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 06-10-2009, 10:52 AM   #1
ne00
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...

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
 
Old 06-10-2009, 12:11 PM   #2
Four
Member
 
Registered: Aug 2005
Posts: 298

Rep: Reputation: 30
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
 
  


Reply


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 03:08 PM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 09:01 AM
Possible to call a shell script within a mysql query? zhjim Linux - Server 2 08-30-2007 03:23 AM
passing a shell variable into awk - syntax for correct interpretation? johnpaulodonnell Programming 3 06-19-2007 01:13 PM
Passing a variable to a cgi script WindowBreaker Slackware 1 04-03-2006 11:02 PM


All times are GMT -5. The time now is 06:24 PM.

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