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