Solved

bash MySQL result into array

Posted on 2013-06-07
2
600 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 37

Expert Comment

by:Gerwin Jansen
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now