Re: Loop on mysql output with bash

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Sun, 18 Mar 2018 18:52:12 -0400
Message-ID: <p8mqin$mv5$1_at_jstuckle.eternal-september.org>


On 3/12/2018 12:24 PM, 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? 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
>

I'm wondering why you think you have to loop and issue another SELECT. I suspect you can get the results you want in one single SELECT statement with proper joining of your tables.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Sun Mar 18 2018 - 23:52:12 CET

Original text of this message