If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL queries from Shell - unexpected result

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-04, 07:38
philipz philipz is offline
Registered User
 
Join Date: May 2004
Posts: 2
MySQL queries from Shell - unexpected result

List,

I have a problem with querying a MySQL database from Shell in batch mode.

I have a file called 'mylist' in this format:
10.156.40.36
10.150.133.33
10.140.159.89


Now with a script I make a Class C of every IP address and put that in a tempfile:
use sitedb
SELECT C FROM sitelist WHERE A LIKE "10.156.40.0";
SELECT C FROM sitelist WHERE A LIKE "10.150.133.0";
SELECT C FROM sitelist WHERE A LIKE "10.140.159.0";

Then I merge the output with the following command:
mysql --silent -h 10.10.10.10 -u username -ppassword < tempfile | paste mylist -

This works extremely well and gives this output:
10.156.40.36 Rome
10.150.133.33 Brussels
10.140.159.89 Amsterdam

However, if for instance 10.156.40.0 (Rome) is not found in the database, I don't get a result for that query (luckily). But my output gets shifted and doesn't match anymore:

10.156.40.36 Brussels
10.150.133.33 Amsterdam
10.140.159.89

In my opinion there are 2 options:
Force MySQL to return 'nill' or something similar if the result of a query is nill (no clue how to do that)

Adapt the script one or the other way so that it checks for a result after each query. Also no clue how to do that

Any suggestion would be greatly appreciated...

Kind regards,

Phil
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On