Shell script logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script logic
# 1  
Old 05-07-2013
Shell script logic

Hi I have a requirement where I have to generate a mail/alert to the user if any QA check is failed.

our oracle jobs run in unix environment and log file is created .
Sample is given below .

Code:
SELECT *
  FROM product.fact_tally
 WHERE period_id = '20130401' ;
 LIMIT 5;

Ideally the above query should return zero but if any output is found the it will be displayed as below

Code:
|20130401	|20	|1	|NETWORK	
|20130401	|20	|2	|NETWORK

this will be stored in the logfile .
Now I have to generate a mail or alert if query output is found and mail the user with which query is failed and the output .

Thanks

Last edited by Scrutinizer; 05-07-2013 at 04:24 PM.. Reason: code tags
# 2  
Old 05-07-2013
systemee, welcome to the forum.

Please let us know where you stuck. Are you able to connect to oracle from unix?
How would you get the query? Do you have more than one query? What might change in the output and what is fixed?

Lastly, regarding email, Do you have email setup configured on your box?
# 3  
Old 05-07-2013
Please use code tags as required by forum rules.

Not clear.
I guess the SQL statement is run from within a shell script. Pls post (the relevant parts of) the script.
Is that output the only contents of the log file, or is it intermixed with other info, perhaps from the rest of the script?
Is the "good" output really zero (numeric 0) or is it empty?
# 4  
Old 05-07-2013
Hi,
Please find the attached sample spool file.
I have mail configured in my unix server and my sql job run in unix environment and I am able to generate spool file from sql query.

My requirement is
if in the spool file contains any output of the query

Code:
SELECT *
  FROM PH1.ENTITY_TALLY
 WHERE period_id = 'M20120801' AND  pc_id = 2
				AND (sessions > hits
					OR sessions = 0)
					;

Code:
M20120701	30	2	61	U	4124817886	mindsecretsexposed.com	2311516391	www.mindsecretsexposed.com	null	1.00000000000000006352	1	0.08060000000000000000	3.00000000000000019056	96.00000000000000000000	0E-20	null	null	
M20120701	100	2	61	U	4124817886	mindsecretsexposed.com	2311516391	www.mindsecretsexposed.com	null	1.00000000000000006352	1	0.01840000000000000000	3.00000000000000019056	96.00000000000000000000	0E-20	null	null	
M20120701	3	2	61	U	4124817886	mindsecretsexposed.com	2311516391	www.mindsecretsexposed.com	null	1572.13351970000000000001	1	0.02490000000000000000	4716.40055910000000000003	96.00000000000000000000	0E-20	null	null

then I have to print/store the above query and output from the spool file.
like

PHP Code:
200>SELECT *
  
FROM PH1.ENTITY_TALLY
 WHERE period_id 
'M20120801' AND  pc_id 2
                
AND (sessions hits
                    
OR sessions 0)
                    ;
M20120701    30    2    61    U    4124817886    mindsecretsexposed.com    2311516391    www.mindsecretsexposed.com    null    1.00000000000000006352    1    0.08060000000000000000    3.00000000000000019056    96.00000000000000000000    0E-20    null    null    
M20120701    100    2    61    U    4124817886    mindsecretsexposed
.com    2311516391    www.mindsecretsexposed.com    null    1.00000000000000006352    1    0.01840000000000000000    3.00000000000000019056    96.00000000000000000000    0E-20    null    null    
M20120701    3    2    61    U    4124817886    mindsecretsexposed
.com    2311516391    www.mindsecretsexposed.com    null    1572.13351970000000000001    1    0.02490000000000000000    4716.40055910000000000003    96.00000000000000000000    0E-20    null    null 
if you see the other queries are not giving any output so I dont need to bother .

like for the below query count(*) is zero so no need to take any action
Code:
62>SELECT count(*) FROM
(
(SELECT * FROM PH1.instance_lvl_info
MINUS
SELECT * FROM PH1.QA_instance_lvl_info)
UNION ALL
(SELECT * FROM PH1.QA_instance_lvl_info
MINUS
SELECT * FROM PH1.instance_lvl_info)
)a;
0	

74>SELECT bk_count, qa_count
FROM (SELECT COUNT (*) bk_count
FROM PH1.instance_lvl_info) a,
(SELECT COUNT (*) qa_count
FROM PH1.QA_lvl_info
) b
WHERE (bk_count = 0
or bk_count <> qa_count);
98>SELECT count(*) FROM
(
SELECT period_id, country_code_id, rn_prefix, instance_id, 
			 gg_cookie_id, imrid, server_timestamp, tag_client_id, 
			 tag_vc_id, tag_media_title, is_dav, tag_ad, count(*)
FROM PH2.lvl_info
WHERE period_id = 'M20130301'
GROUP BY period_id, 
	 country_code_id, 
	 rn_prefix, 
	 instance_id, 
	 gg_cookie_id, 
         imrid, server_timestamp, 
	 tag_client_id, 
	 tag_vc_id, 
	 tag_media_title, 
	 is_dav, tag_ad
HAVING count(*) > 1
) a;
0

# 5  
Old 05-14-2013
can someone please help if this logic can be handled by shell scripting
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Help with shell script on Month Changing Logic

Hi Unix Experts, Happy Morning to all !! :) I am new to UNIX Shell Scripting and at my begineer level. To get acquainted to scripting, I am trying to create a script. The details/requirements of my script was to create a script with month changing logic in it so that on every 6th Working... (3 Replies)
Discussion started by: micky3112
3 Replies

3. Shell Programming and Scripting

Restart Logic for a Korn Shell Master Script

Hello All, I was wondering if someone can help me to develop restart logic for a Korn Shell program (a master script) that I am developing. The program is design to invoke a series of child processes (Korn Shell Scripts) whose function is to create a series of load files on a specified mount... (0 Replies)
Discussion started by: jonesdk5
0 Replies

4. Shell Programming and Scripting

Logic in Shell script required

Hi, I have the following in my shell script sqlplus << EOF username/password @$SCRIPTS_DIR/refresh.sql > /home/oracle/sql/refreshsql.log EOF RETCODE=$? if ; then echo "ERROR: sqlplus command finished with error code {RETCODE}" /usr/bin/mailx -s "REFRESHING FMLA CONTACT... (2 Replies)
Discussion started by: welldone
2 Replies

5. UNIX for Advanced & Expert Users

Network Shell Script & Blade Logic & Network Security

I am going to take up a position in Data & Network Security. I would need to write network shell scripts doing the following task: Going to around 2000 servers and findout which groups has access to each servers and which ids are there in each group that has access. I need to implement... (1 Reply)
Discussion started by: pinnacle
1 Replies

6. Shell Programming and Scripting

Shell or PERL Logic

Hello All, Currently i am working on a logic in PERL scripting ... But i am sort of stuck up, can any one please help. Here goes. 1. Search for a pattern in a file 2. If the pattern matched lets say 10 lines 2.1 Reterive the first line and check for another pattern 2.1.1 if... (1 Reply)
Discussion started by: maxmave
1 Replies

7. Shell Programming and Scripting

Query on a shell script logic

Hello people, I am new to shell scripting and hoping to get a quick answer to my query. I am writing a simple script which needs to call an executale which generates an output file. Once the output file is generated I have to do a couple of more task with that file. The executable ideally... (1 Reply)
Discussion started by: tipsy
1 Replies
Login or Register to Ask a Question