Re: Loop on mysql output with bash
Date: Mon, 12 Mar 2018 13:25:20 -0400
Message-ID: <p86d60$c94$1_at_dont-email.me>
Boubaker Idir wrote:
> Hello everybody, I need to do a loop on my mysql output (packetid) and put
> it everytime on the second SELECT command, to have a result for each
> packetid and put it everytime on text file. can you help me please?
Without seeing how you've defined your database (myDatabase) and table(s) (wifi), I can't be certain how to help you. In any case, I believe that your solution (below) probably is overkill for what you want to do, and there might be a one-line solution that would work as well or better.
At a minimum, could you please post the results of USE myDatabase; EXPLAIN wifi;
and the same for any other tables referenced by columns in table wifi?
With that, I might be able to suggest an appropriate SQL query for you.
> Thank
> you so much
>
>
> #!/bin/bash
> array=$(mysql -u root -pMyPassword -s -N <<QUERY_INPUT
> use myDatabase;
> SELECT packetid FROM wifi;
> QUERY_INPUT
> );
>
> echo "${array[_at_]}";
>
> for i in "${array[_at_]}" do
>
> variable=$(mysql -u root -pMyPassword -s -N <<QUERY_INPUT
> use myDatabase;
> SELECT CONCAT("{""wlan"":
> [",GROUP_CONCAT(JSON_OBJECT("mac",bssid,"powrx",rssi)), "]}") FROM wifi
> WHERE packetid=$i; QUERY_INPUT );
>
> echo $variable>text2.txt;
> done
-- Lew Pitcher "In Skills, We Trust" PGP public key available upon requestReceived on Mon Mar 12 2018 - 18:25:20 CET