how to use IF-THEN within csh script to check Db counts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to use IF-THEN within csh script to check Db counts
# 1  
Old 04-09-2009
how to use IF-THEN within csh script to check Db counts

hi everyone, rookie scripter here. Under some time pressure here and hoping you can help. I've written a .csh script that needs to check a row count in an Oracle table, then do an IF-THEN check against that count. Two different select statements actually, one after another. If either of the two counts fail to meet expectation, I want to exit the script. Here's what I have:

#!/bin/csh -f
source ~/.cshrc
#
echo `date` "+--------------> "Command was `basename $0`\.
set USAGE="USAGE=ltz_check_eodevent_process.csh"
set SQLPLUS = ${ORACLE_HOME}/bin/sqlplus
echo `date` " starts sql query for checking the EOD counts"
${SQLPLUS} -s << EOF
$DB_LOGIN
SET VERIFY OFF
SET TERMOUT OFF
SET ECHO OFF
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET LINESIZE 300
SET PAGESIZE 200
SET COLSEP ' '
SET SERVEROUTPUT ON SIZE 999999
WHENEVER SQLError EXIT FAILURE

select count(1) as count_of_rows from put_groups where group_name='PC'
and description='EOD_EVENT' and serial_number=1;

IF count_of_rows < 1 THEN
raise_application_error(-20001,'EOD message for PC not found');
END IF;

select count(1) as count_of_rows from position_intraday where
added_date like to_char(sysdate,'YYYYMMDD')||'%' and pre_eod_flag is null
and added_by='MSG-PC' and to_date(substr(added_date,1,12),'YYYYMMDDHH24MI') <=
(select to_date(substr(element_value_1,1,10)||substr(element_value_1,12,8),'YYYY-MM-DDHH24:MI:SS')
as msg_date
from put_groups where group_name='PC' and description='EOD_EVENT' and serial_number=1);

IF count_of_rows > 0 THEN
raise_application_error(-20001,'EOD message for PC was not processed correctly);
END IF;

EOF
#
success:
echo " "
echo `date` "+++++++++> ltz_check_eodevent_process.csh finished successfully."
echo `date` "---------------> "`basename $0` done\.
echo " "
exit 0

failure:
echo `date` "=========> ltz_check_eodevent_process.csh failed."
echo `date` "---------------> "`basename $0` done\.
exit 1
########################

The problem is, the IF-THEN block is not being recognized. The select statements are both valid and they are working within this script, but it's not exiting. Ideally, I'd like to use "goto failure" if the count doesn't meet what I want. I don't need to create files or send any emails. Just look at the count, proceed to next select/check OR exit via failure.

Maybe I need a BEGIN-END block somewhere? Help? THANKS!!!
# 2  
Old 04-09-2009
It looks to me like you are attempting to use shell if-then logic inside your SQL code. Since you've turned off all the notifications, you are not seeing the error messages that this will surely generate.

If I am reading the code correctly, you will want to either replace those IF-THEN statements (which are not valid in SQL) with the Oracle-specific DECODE structure. The DECODE is not a true IF-THEN-ELSE, but can usually be made to work with some tweaking.

Alternatively, you could run your select statements and redirect the output to an OS file which you can then analyze with a shell script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

DB2 Query to check table counts,start end time

Dear team I am using DB2 and wish to capture the ETL status on daily basis so that i can run the query and share the details in xls format to respective mail ids . Currently i am using below query but this displays table name and counts for latest run. select name ,CARD from... (0 Replies)
Discussion started by: Perlbaby
0 Replies

2. Shell Programming and Scripting

Csh/tcsh : Check the file existance and run the script

Hi, I've to wait until a file generated and once its generated, source another script in Linux terminal. Please help me as this is very very urgent. The code should be something like if ( -e "/abc/xyz/a.txt ) source aaa.csh else sleep This should be repeated till the if... (4 Replies)
Discussion started by: kumar_eee
4 Replies

3. Shell Programming and Scripting

UNIX/Perl script to call informatica source counts

Hi Guys, I am trying below condition . We are using Informatica 9.5 and scheduling certain informatica mapping on set timings .But we are not sure whether the database source table are latest or not .Since its gets updated on daily basis and not sure when it completes.Can we write any unix/perl... (1 Reply)
Discussion started by: Perlbaby
1 Replies

4. Shell Programming and Scripting

csh Check if file exists on remote system

I've seen this question posed a few times with shell scripting, but have not found anything with csh. I am trying to download multiple txt files from a source using wget. These are archived tornado warning files; however, the files only exist if there were tornado warnings issued that day. I'm... (3 Replies)
Discussion started by: meteorologistks
3 Replies

5. Shell Programming and Scripting

How to check existence of variable in csh

Hi All, I want to check existence of variable, whose name gets decided dynamically. E.g. value of this variable,is derived as $option_"exclude" , where value of option varies depending upon user input. I am trying to do it in a following way : set exclude_var = `echo $option"_exclude"`... (3 Replies)
Discussion started by: Rashmee
3 Replies

6. Shell Programming and Scripting

Script to compare table counts...

Hello all, I am very new to unix. I am working on a DB upgrade. The requirement is to get count of all the tables in the database before and after upgrade and compare them. I found the below query to find the counts of all the tables: nawk -v v="'" '{ print("select " v ":" $1":" v... (2 Replies)
Discussion started by: vkrisaak
2 Replies

7. Shell Programming and Scripting

csh if loop variable condition check peroblem

Hi, I have variables like var1 var2 var3 var4 in if loop i am trying to check the condition if(variable == "var") then echo $variable endif (0 Replies)
Discussion started by: vasanth.vadalur
0 Replies

8. Shell Programming and Scripting

Perl script that counts lines of a file

I am working on this script, but hit a bump. Looking for a little help figuring out the last part: open(MY_FILE, $ARGV) or die $COUNTER = 1; $LINE = <FILE>; while ($LINE, <FILE>) { # Adds leading zeros for numbers 1 digit long if ($COUNTER<10){ print "000"; } # Adds... (2 Replies)
Discussion started by: Breakology
2 Replies

9. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

10. Shell Programming and Scripting

Csh to check for existence of file

Hi, I would like to check the existence of files (doesn;t matter the number of files) in a directory. My file is named in the following manner (always ending with " myfile "). Can anybody give me some guidance? EG: abc1_myfile sdfr_myfile sffgd_myfile and so on ...... My... (9 Replies)
Discussion started by: Raynon
9 Replies
Login or Register to Ask a Question