Programming :: Looping Over Mysql Query Results In Bash?
Sep 15, 2010
I am querying a single string column in a table. The string values have spaces in them. I want to loop over each value in bash. I set IFS to split lists on newlines instead of spaces. When I try this, it is splitting the list of results on the actual character 'n', not the newline ''.
DATA=`mysql -u root -ppassword --silent 'SELECT name FROM table_a;'`
IFS=$'
'
for i in $DATA; do
echo "item = $i"
[Code]....
View 5 Replies
ADVERTISEMENT
Feb 7, 2010
how do I achieve the result but here is the story. I have a script which prompts for the IP Address and read that value and validate if reachable. If not then it should keep on prompting until the IP is reachable. I tried using until loop as well as while loop but dang..Here are the codes
#!/bin/bash
IP_Feed () {
echo -n "Give me IP : "
[code]....
View 4 Replies
View Related
Apr 26, 2010
I have created a database which stores students grades for different stages of a project. One of the stages of the project is the specification part. I have a simple bit of html code which is going to be used as the searching facility. I want the user to be able to enter their ID and then it will display only their results. At the moment, it is displaying the results for EVERY student because I cant seem to find the correct syntax for my statement.
Heres the HTML code
<html>
<head>
</head>
<body>
<body bgcolor="#6881bb">
<center>
[Code]....
At the moment when i click the button, no matter what I enter every students marks appear on the screen.
I think, but obviously dont know for sure because if i did i would know how to solve the problem, the code that i need to change is in green.
View 3 Replies
View Related
Jul 12, 2011
When i enter this query to mysql:
Code:
return this error:
Code:
when i delete the insert part :
Code:
query is ok:
Code:
1 row in set (0.00 sec)
View 2 Replies
View Related
Dec 2, 2010
Trying to export a Mysql query to a .csv file the query draws from multiple tables, e.g. sales, purchase and currency
Code:
What i'm trying to do is to export both the sales and purchase to a single line where both the currency for the sales and the purchase is specified.
Basically like this:
Code:
Problem here is that i'm stating currency.value twice in the same select and don't know how to define which currency.value applies to sales and which to purchase.
View 7 Replies
View Related
Jan 29, 2011
It is under PHP/MySQL
$queryresult = $conn->query("INSERT INTO normalrequests VALUES($finalkey, 1234, 5678, FALSE)");
It is connected to the database successfully but I feel there is something wrong with the statement up there.
View 6 Replies
View Related
Jul 27, 2010
i will be quick, im trying to send a mysql query output into an array ie:
Code:
declare -a HD
HD=`echo "USE db; SELECT uid FROM user" | mysql -u $login -p$pwd -h $dbhost -B`
echo ${#HD}
those vars in mysql connection are previously and correctly assigned.
but got an error
script.sh: 2: declare: not found
View 3 Replies
View Related
Oct 17, 2010
I am not sure if this is possible. I have IP's stored in a mysql database. When I query the database, it returns the IP. I would like to replace the IP with something else prior to displaying the results. Is it possible even though I have not stored it in the database?
I have the following in a while loop (mysql_fetch_array).
Code:
<td align="left">' . $row[IP] . '</td>
Instead of displaying $row[IP] from the database, I would like it to display something else which I define in the PHP code but based on the IP.
ie. aaa.bbb.ccc.ddd = hostnameABC
View 4 Replies
View Related
Feb 22, 2011
So I've got a rather vast database, one of the columns is date in the following format: DD/MM/YY HH:MM:SS. This is starting to cause problems with a php page I'm writing which asks the user for a 'start date'. Would it be better for me to split the date column into date and say time? Or is there a way of using distinct and masking the times.
View 10 Replies
View Related
Jan 20, 2009
How do I find for example the 4th to the 9th result in a particular SELECT query?
View 6 Replies
View Related
May 5, 2011
(bare with me as I am sort of new with scripting) I am trying to figure out how to run a script that does a basic chkconfig and to get only those services that are running, but changing the color of "on" to red in my output file. Here is what I am working with so far:
Quote:
#/bin/bash
RED=$(tput setaf 1)
BLK=$(tput setaf 0)
[code]....
*I had to substitute a "-" and <colon_symbol> for ":" in front of the on's, because the forum thought they were smiley faces (i.e. n) how to make the "on" to be red while the rest of everything remains in black text. I have been trying to read up on sed and awk, but it is still pretty much a mystery to me right now. There will be other things in the output file that I wouldn't want a rogue "on" to be in red, so just the instances of "on" in that one chkconfig return.
View 4 Replies
View Related
Nov 2, 2010
I've written a bash script to connect to each machine in our local network and update the fstab file to point certain NFS mounts to a new location.The script is meant to read in a list of shares and a list of workstations, rsync the relevant share then connect to each workstation and update the fstab file before moving onto the next share.In reality what is happening is it will perform the loop correctly for the first workstation in the list but will not move on to the next one. I'm really stumped on this and I'm sure it's something simple but I just can't seem to work out the answer!
Code:
#!/bin/bash
SHARES=$1
[code]....
View 6 Replies
View Related
May 27, 2011
I have a simple .bashrc backup script I've been working on, but my external hard drive needs to be plugged in for it to work. So I set up a while loop, that exits after the hard drive has been plugged in and backed up. Here it is:
Code:
#/bin/bash
pluggedin=1
[code]....
View 4 Replies
View Related
Jun 8, 2010
how to set the subject of this up.. but here is what I am trying to accomplish (please keep in mine, this is only my first month playing with ANY Linux programming): My shared web host limits running 2 CRONS or 2 SSH sessions at one time. I need to run more than that.. So, my solution is to run what I need on my home computer, and then push all the results via SSH to my web server.
To keep things timed, I am trying to call 4 bash scripts from inside of 1 bash script... Each bash script has variables I need to export out to the remote (web) server. Being that I can only run 2 SSH or 2 CRON sessions on the remote, it wouldn't do me any good to open up CRON or SSH remotely or locally - either way I'm maxing out. That is why I would like to call 1 final script that takes the output of the 4 bash scripts and does the job.
Main bash calls via CRON every 30 minutes:
Code: ./script_1 &
./script_2 &
./script_3 &
./script_4 &
[code]....
I need to scp the file saved by wget to the remote server. I also need to pass the SQL statement generated in each script as a command in SSH. I'm lost how to get the info from "script_x" into a string that can be used to SSH - and doing this all inside of ONE SSH command. Would I store the SQL strings in a file and call that in the SSH command line?
If so, what is the command to make sure the variable output in the "script_#" file is sent to a file? Can I call the variable from the main Bash Script? Now - the good news is, I can SSH from my local machine to the remote one.That is about as far as I got.Again - I am so new to this that my ears are still wet. This has been something I have been working on for a while, and I'm just lost at this point.
View 2 Replies
View Related
May 26, 2011
I need to know how to assign a result from a select. I am clueless on the sytax. I am trying this in bash. Maybe I am not assigning the array right. It gives me the whole row in the echo instead of just field a. How do I get fieldA = a in the select. Note script was stripped for security on database info but the syntax is same.
Code:
#!/bin/sh
results="$(mysql --user ${DB_USER} -p${DB_PWD} ${DB_NAME} -Bse 'select a,b,c,d from tblMytable')"
for rows in "${results[@]}"
do
fieldA=${rows[0]};
echo ${fieldA};
done
View 2 Replies
View Related
Apr 25, 2010
I'm trying to get a password in a bash script for mysql user creation. But sometimes a get a non-alphanumeric character(s) in the password, and mysql failes with that. I tryed with apg -EO0Il1`~!@#$%^&*()_+-=[];./{}|:"'<>? but failed. I tryed with sed 's/[^a-zA-Z2-9]//g' , but at that moment the minimum password lenght failed. I'm also fine when there is a better alternative then apg.
View 2 Replies
View Related
Apr 14, 2011
Can query browser be installed in 11.4??
I've tried to use workbench but it's such a big step backwards in that you can't easily edit the output from a "select x,y,z from table" query. I'd have thought that was a pretty basic requirement...
View 5 Replies
View Related
Sep 24, 2010
I created the following.
x="top
middle
bottom"
I would like to make the following work.
while read line
do
echo $line
done
instead of importing a file I would like to use the variable $x I tried using pipes, but with no luck. My goal is to read one line at a time, but not have to export my data to another file, I would like to keep it all within one script.
View 3 Replies
View Related
Sep 21, 2010
I have the following mysql query which works great.
Code:
SELECT msg FROM `logs` WHERE ((`host` = 'aaa.bbb.ccc.ddd') OR (`host` = 'aaa.bbb.ccc.ddd')) AND `msg` REGEXP CONVERT( _utf8 'physical addresses' USING latin1 ) COLLATE latin1_swedish_ci
I need to refine this query so that I can query the last # hours using the `datetime` field in the database. I have researched the DATE_SUB function and can query for example the last 1 hour like this:
[Code]....
View 10 Replies
View Related
Jan 17, 2011
I am on a CentOS 64 bit and used webmin to rotate MySQL slow query log. Now the thing is although logs are being rotated daily but the new log files being created are empty which means MySQL is unable to write them due to some reason. I have checked using "ls -l" that both permission and owner of files is same but still MySQL is not writing logs. What could be the reason?
View 10 Replies
View Related
Jan 28, 2010
i have MySQL on my CentOS server and have installed it and got it up and running through the command line.
I have changed root's username and password so there is no user called 'root' anymore. I also created a database called pancakes.Now when i try to log in using Query Browser, i put the server's IP in 'hostname', my new roots username and password in 'username' and 'password'.When i try to log in it gives me error 1130 and says connection from myhostname not allowed.
View 6 Replies
View Related
Nov 3, 2010
I want to itemize addition for each type of transactions. The example below is for 3 days,10/13/2010, 10/14/2010, & 10/15/2010.
PROD =89.25+89.25+104.47= 282.97
TAX =9.37+9.37+10.37 = 29.71
ETAX = 1+1+1 = 3
[code]...
View 8 Replies
View Related
Mar 17, 2011
I want to install mysql query browser in debian
View 1 Replies
View Related
Jun 28, 2011
I have an Excel Spreadsheet which reports upon weekly performance. One portion of the worksheet looks at week over week increases /decreases. I've placed a number of image controls (15 in Total) next to cells which calculate week over week change. The image controls simply display an image depending on whether the value of the adjacent cell is positive or negative. So, here is my basic working IF statement:
Code:
Private Sub Worksheet_Change(ByVal UpDown As Range)
If Range("J26") > 0 And IsNumeric(Range("J26").Value) Then
Image1.Picture = LoadPicture("C:path oup_arrow.gif")
ElseIf Range("J26") < 0 And IsNumeric(Range("J26").Value) Then
[code]....
As you can see, this is pretty simple. What I'd like to do is find a way to loop through all 15 controls and avoid having 15 IF statements run on the Worksheet_Change() event. The cells containing the week over week values are all in the same column, but not continuous. Involved cells are: ("J26", "J27", "J33", "J34", "J35", "J36", "J37", "J38", "J39", "J40", "J42", "J43", "J44", "J45", "J46")
View 6 Replies
View Related
Aug 31, 2010
I am using MySQL 5.0.77 Version rpm on CentOS 5 Red Hat Linux. I want to install micro second slow query log patch on this MySQL S/W version.As I found the slow query micro second patch on percona site i.e. [URL]step by step to install above mentioned patch with rpm based MySQL installation? Do we need MySQL source files to apply patch ?
View 13 Replies
View Related
Jan 16, 2011
Does anyone know where I can get a link to download MySql query browser(windows version)?
I want to query my database on my fedora box in windows to make life easier... I can not seem to find a link to download the query browser though
View 2 Replies
View Related
Nov 17, 2010
I am running Ubuntu 10.04 LTS. I am trying to run a query browser for mysql but keep receiving the following error:
X11 connection rejected because of wrong authentication.
The application 'mysql-query-browser-bin' lost its connection to the display localhost:10.0; most likely the X server was shut down or you killed/destroyed the application.
In ssh_config, I do have ForwardX11 set to yes.
View 4 Replies
View Related
Mar 1, 2011
I need help about the error in my website. I have the following error....
Code:
user warning: Got error 134 from storage engine query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'theme_registry:database1' in /var/www/html/web/includes/cache.inc on line 26.
View 2 Replies
View Related
Mar 14, 2010
I am using "if" to force a word under the condition that the first letter of that word must be a letter of the alphabet, regardless of capitalization, using the " "" != "" " syntax.
Like so:
Code:
if [[ "$interface" != "WHAT DO I PUT HERE?" ]] ; then
echo "Invalid input"
exit 1
fi
View 5 Replies
View Related
Feb 13, 2011
SU results in Cannot execute bash: No such file or directory.
View 1 Replies
View Related