I have a problem with querying a MySQL database from Shell in batch mode.
I have a file called 'mylist' in this format:
Now with a script I make a Class C of every IP address and put that in a tempfile:
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:
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:
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...