473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to store Mysql Database Field value to Shell Script variable

Hi Bytes.. i have need to assign Mysql Database DataField value to shell script variable .

is it possible ? i have tried like this .. got error..
Expand|Select|Wrap|Line Numbers
  1. #!bin/sh
  2.  
  3. password=xxx
  4. mysql -u root -p$password -h 192.168.1.8 << y
  5. use dbssys;
  6. d ="`select mem from profile` ";
  7. echo $d
  8. quit
  9. y
  10.  
  11.  
Got Output like this..

test.sh: command substitution: line 1: syntax error near unexpected token `from'
test.sh: command substitution: line 1: `select mem from profile'
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd =" "' at line 1
Jan 2 '09 #1
8 13634
micmast
144 100+
The problem is that the backticks will execute the code within and select mem from profile is no valid linux bash/shell command. Try escaping them with a \
Jan 2 '09 #2
i cant get you clearly.. if you dont mind..can you please correct that particular line and send me ..
Jan 2 '09 #3
micmast
144 100+
micmast@plato:~$ d="\`select mem from profile\`";
micmast@plato:~$ echo $d
`select mem from profile`
Jan 2 '09 #4
Hi i didnt solve the problem yet.. after applying changes that you have said.. any other solution for this..
Jan 6 '09 #5
gpraghuram
1,275 Expert 1GB
Why canyou use isql or fsql to connect to the DB and get the values to the variable you expect?

raghu
Jan 7 '09 #6
i am not using fsql or isql for my project. actually i am doing Linux system oriented project and storing the values in Mysql . i need to compare the values that stored in mysql and recent values get from the linux .. so thats why i am looking for a solution? can u suggest some hint ? method /way proceed further??
Jan 7 '09 #7
ashitpro
542 Expert 512MB
Try using this line...

result=$(mysql -u $user_name $db_name -p$password -sN -e “select mem from profile”)
Jan 7 '09 #8
In a script just write this, and play with the mysql options to get what you want.

SHELLVARIABLE=`mysql --skip-column-names dataBase -e "SELECT COUNT(*) from TableAAA"`

and then u can do somethink like

ehco $SHELLVARIABLE

This is a tip.

Bye.
Dec 15 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
20
by: de Beers | last post by:
mysql_query("DELETE FROM cart WHERE ItemId=$ItemId"); There is the code but the result in my databse is that the ID number changes from, lets say, 77 to 78 with 78's contents being empty. ...
2
by: RootShell | last post by:
Hello First of all i know that PHP is a server side, and JavaScript is a Client side programming language, but i need to know if there is any way i can add the variable "countDownInterval" from...
3
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
JamieHowarth0
by: JamieHowarth0 | last post by:
I have been trying to find a solution to this on the Internet for months. Literally, ages and ages and ages, praying that someone in the open-source community has enough knowledge to put together an...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.