How to capture the error code a use it in error table?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to capture the error code a use it in error table?
# 1  
Old 08-04-2015
How to capture the error code a use it in error table?

Hello Everyone,

I have written a file validation script in unix to compare the data and trigger file.My requirement is if the file validation fails,I need to upate the error details in a table

ex:Below is the one of many validation checks i am doing
Code:
if [ $data_file_cnt -ne  $trg_file_cnt ]
then
echo "Actual count between $data_file and $trigger_file not matching [fail the process]\n" >> $OUT_FILE
exit 10
else
echo "Actual count matching between $data_file and $trigger_file\n" >> $OUT_FILE
fi

So for example if the counts are not matching,it should fail the process(exit 10) and then insert into error table (which i can do it via sql plus,wer in i have added id 10 as count not matching in table).

My doubt is, how can i capture the exit code and display it in the table since it will exit out of the program Can i store it in a temp variable and apply it in insert?

Code:
ex: sqlplus user/pwd
 insert into error table values ($exit status,' ')

Kindly let me know if you need more information
# 2  
Old 08-04-2015
Not sure I understand. Do you want to exit that script and use the exit code in a parent script or do you want to update the DB table in that same script?
# 3  
Old 08-05-2015
Hi,


I need to capture the error code before exiting the program.

Code:
if [ $data_file_cnt -ne  $trg_file_cnt ]
then
echo "Actual count between $data_file and $trigger_file not matching [fail the process]\n" >> $OUT_FILE
fn_insert_error_table 10
exit 10
else
echo "Actual count matching between $data_file and $trigger_file\n" >> $OUT_FILE
fi

fn_insert_error_table()
{
now=`date +"%m-%d-%y %H:%M:%S`
`sqlplus -s $DB_USER@P1TFDDS/$DB_PWD<<EOF
INSERT INTO error_table(DQ_EXCEPTION_DEFINITION_FKID,INSERT_TS)
VALUES($1,$now);
commit;
EOF`

wherin it will insert 10 before exiting the program,Could u please let me know how i can pass the parameter and insert it inside the function in unix.
# 4  
Old 08-05-2015
On first sight, after removing the backticks around the sqlplus command, it might fly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture error before pipe

Hi, I have a script that runs a tar command to standard out then pipes to a gzip: tar cfE - * | gzip -c > OUT.gz At the moment, even if the tar fails (e.g. because of lack of disk space), the gzip still runs successfully. Is there a way to make the whole line exit with a non-zero error... (6 Replies)
Discussion started by: Catullus
6 Replies

2. UNIX for Dummies Questions & Answers

How to Capture Informatica Error logs?

HI Team , Is there a way to capture information logs ( session or workflow ) and grep only ERROR or FAIL messages and send to email distro using mailx or sendmail option. I have around 200 sessions running on daily basis and this script has to run every day , and capture only error... (0 Replies)
Discussion started by: Perlbaby
0 Replies

3. UNIX for Dummies Questions & Answers

Capture crash out error report...

Google is not helpful here. It is probably trivial but I can't get my head around it. How do I capture an error which crashes out due to say a syntax error to a file? (Note that I manually reset error.log to zero length.) Consider this junk code:- #!/bin/sh # Launch as ./trap.sh... (2 Replies)
Discussion started by: wisecracker
2 Replies

4. Shell Programming and Scripting

Not able to capture error while using dialog

I am not able to capture errors while I am using dialog. For example: dialog --gauge "Verifying file..." 10 75 < <( while read LINE do hash=$(echo $LINE | cut -f1 -d' ') directory=$(echo $LINE | cut -c 34-) PCT=$(( 100*(++i)/n )) echo $PCT md5deep -a $hash $directory >... (3 Replies)
Discussion started by: yamanoorsai
3 Replies

5. Shell Programming and Scripting

Need to capture error of sybase isql in unix

Hi Gurus, I am very new in Unix, I have 1 script, in which I am truncating the table , then BCP the data in Sybase table, and then loading the data from sybase table to sybase table. every thing is working fine, but the problem is with Error. I made some hanges in my insert statement so... (3 Replies)
Discussion started by: aksar
3 Replies

6. Shell Programming and Scripting

Need to capture error of sybase sql in unix

Hi Gurus, I am very new in Unix, I have 1 script, in which I am truncating the table , then BCP the data in Sybase table, and then loading the data from sybase table to sybase table. every thing is working fine, but the problem is with Error. I made some hanges in my insert statement so... (1 Reply)
Discussion started by: aksar
1 Replies

7. UNIX for Dummies Questions & Answers

Capture Error In SQL Plus

Hi I am trying to fetch the data from Oracle Table More my_query.sql | sqlplus -s 'scott/tiger@OrcaleSID ' | sed 's///g;s///g' > sample_file Now if the table passed in the my_query.sql is wrong or there is some other error insied SQL how i can caputure that i tried More... (1 Reply)
Discussion started by: max_hammer
1 Replies

8. Shell Programming and Scripting

database instance Error capture

I wrote a script to capture some rows from the DB. However I want to capture the errors if the DB instance is down which usually produces errors like below. What should be my approach to kill script if the DB instance is down: DATABASE ERRORS: Msg 937, Level 14, State 1: Server... (2 Replies)
Discussion started by: moe458
2 Replies

9. Shell Programming and Scripting

Capture Schell script error

I work on AIX 5.x. I have a script which does lot of processing & calls multiple child scripts. How do I capture the error of the parent script if it fails? Thanks Sumeet (3 Replies)
Discussion started by: sumeet
3 Replies

10. Shell Programming and Scripting

sqlplus -s error capture

Hi folks a wee problem that requires some help. I am writing a script that allows me to automate the changing of a password in sqlplus the problem i encounter is that the code contains a case statement that allows the helpdesk to select whether to allow or deny access by switching the... (1 Reply)
Discussion started by: w33man
1 Replies
Login or Register to Ask a Question