Solved

bash MySQL result into array

Posted on 2013-06-07
2
611 Views
Last Modified: 2013-07-23
I have a script that runs every 15 minutes which looks for phone calls in a database and groups them by the sourceTN counting calls.  The query and result is below.  My questions is I need to be able to store each row (sourceTN and Calls) into a temporary variable so I can crank it through and IF statement to see if a telephone number has a value greater then 10.  Something like...

IF Calls > 10
THEN
  # do some actions with the SourceTN


Query:
SELECT src as SourceTN, COUNT(src) as Calls FROM cdr GROUP BY src;"

Open in new window



+------------+-------+
| SourceTN   | Calls |
+------------+-------+
| 2012680000 |    27 | 
| 2016240000 |     1 | 
| 2018160000 |     2 | 
| 2018160000 |     5 | 
| 2018160000 |     7 | 
| 2018160000 |     9 | 
| 2018160000 |     1 | 
| 2018160000 |     4 | 
 

Open in new window

0
Comment
Question by:ipconfig610
2 Comments
 
LVL 6

Accepted Solution

by:
Manuel Marienne-Duchêne earned 500 total points
ID: 39228766
SELECT SOURCETN,CASE WHEN CALLS > 10 THEN ....ELSE .... END FROM (SELECT src as SourceTN, COUNT(src) as Calls FROM cdr GROUP BY src) TABLE1
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 39232698
Where is the output of your query going? To some temporary file perhaps?

In case the output goes to a temporary file, you could parse the file and search for lines matching your 'clause' > 10 calls using awk for example.

If possible can you post (part of your) script?
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question