UNIX with DB2 error status Issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX with DB2 error status Issue
# 1  
Old 02-02-2018
UNIX with DB2 error status Issue

I have a shell script main.ksh We are calling dbscript.ksh from main.ksh
I am using select statement in dbscript.ksh but there is a problem with the select statement in dbscript.ksh but still echo $? is showing as zero. I am using DB2 commands in dbscript.ksh

Code:
Main.ksh
dbscript.ksh
echo $?  #it is returning zero even though error is there in dbscript.ksh


Last edited by rbatte1; 02-02-2018 at 08:05 AM.. Reason: Added some formatting for clarity.
# 2  
Old 02-02-2018
This is probably because there is no error checking in dbscript.ksh.

Can you share that so we can consider it? Feel free to obscure and userid/passwords if you have them embedded in the script.


Thanks, in advance,
Robin
# 3  
Old 02-05-2018
dbscript.ksh script details are mentioned as below.In this script also
$?is giving 0 and there is error in db2 select command

Code:
echo "Start Timestamp is : "$datevar1 > log.out;
db2 "export to $exportfilepath/abc.ixf of IXF
select * from table with UR" #Here I am selecting from various tables and conditions
datevar=`date +'%F-%H.%M.%S'`
echo "Current Timestamp is : "$datevar >>  log.out;
echo "The value of $?" # Here also it is returning 0
if [[ $? -ne 0 && $? -ne 2 ]]; then
        echo "Run Status is : Fail"
else
        echo "Run Status is : Success" 
fi

# 4  
Old 02-05-2018
The $? shell variable holds the exit code of the LAST command executed, i.e. the echo in above. Save the individual exit codes into separate variables right after the respective command, like e.g.
Code:
db2 . . .
EXIT_DB2=$?
select . . .
EXIT_SEL=$?

and do an error handling based on those, or return either to the caller.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 02-05-2018
Thanks for Input.Now dbscript.ksh is working fine but the problem is main.ksh is not working.Main.ksh should display dbscript.ksh got failed but it going to else part.Both script are mentioned as below

dbscript.ksh
Code:
db2 "export to $exportfilepath/abc.ixf of IXF select * from table with UR" #Here I am selecting from various tables and conditions.There is an error and it is working fine
if [[ $? -ne 0 ]]; then
        echo "Run Status is : Fail"
else
        echo "Run Status is : Success" 
fi

clarification:-Why it is going to else part is not clear to me?
main.ksh
Code:
dbscript.ksh
if [ $? -ne 0 ];
then 
echo "dbscript.ksh got failed` 
else 
echo "dbscript.ksh got succeed"
fi

# 6  
Old 02-05-2018
The $? shell variable holds the exit code of the LAST command executed, i.e. the echo ... Fail in above. Save the individual exit codes into separate variables right after the respective command . . . return either to the caller.
# 7  
Old 02-05-2018
Could you please help on How to do Save the individual exit codes into separate variables right after the respective command . . . return either to the caller.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to track table status delete/update/insert status in DB2 V10 z/os?

Dear Team I am using DB2 v10 z/os database . Need expert guidance to figure out best way to track table activities ( Ex Delete, Insert,Update ) Scenario We have a table which is critical and many developer/testing team access on daily basis . We had instance where some deleted... (1 Reply)
Discussion started by: Perlbaby
1 Replies

2. Programming

DB2 - Performance Issue using MERGE option

Dear Team, I am using DB2 v10.5 and trying to load huge data using MERGE option ( 10-12 Million) using below query. Basically it loads data from staging to target . Staging table schemaname.Customer_Staging has 12 Million records . Runs for 25 Mins for just select query. But while doing merge... (2 Replies)
Discussion started by: Perlbaby
2 Replies

3. Shell Programming and Scripting

Issue on executing db2 queries through shell script

hi i am trying to execute db2 queries through shell script. it's working fine but for few queries is not working ( those queries are taking time so the script is not waiting to get the complete the execution of that query ) could you please any one help me on this is there any wait... (1 Reply)
Discussion started by: bhaskar v
1 Replies

4. Shell Programming and Scripting

/db2home full issue in db2

Hi all, I am new for linux environment, and i am working as a DBA. I am facing some issues in OS level: In our dev boxes /db2home under this directory i'm not finding any folder but it's showing 98% used . /dev/dm-14 5.0G 4.6G 115M 98% /db2home # ls -lrt total 16... (1 Reply)
Discussion started by: suresh_target
1 Replies

5. UNIX for Dummies Questions & Answers

How to connect to DB2 using UNIX

I am new to Putty, Unix and DB2 and this is what I am working on right now. I installed Putty I got access to username / pwd I got Unix usrname/Pwd.also got the home directory once I login into putty I get the screen and it shows $ sign From here how do I connect to DB2 database? I have... (2 Replies)
Discussion started by: JayDoshi
2 Replies

6. Shell Programming and Scripting

Unix and db2 where condition issue(new line)

Hi I am extracting a column value(DESCRIPTION) from one table and passing it to another db2 statement in a shell code to fetch some value(ID) but the value when passed in where condition is taking as newline+value. Please find the out put when executed: + echo description is ::::... (1 Reply)
Discussion started by: msp2244
1 Replies

7. Shell Programming and Scripting

DB2 Connect issue

Hi i m trying to connect DB2 via unix. it is successfully connect. but the connect is getting disconnect . below is the query , countvalue=$(db2 "connect to <Database> user <username> using <Password>" | db2 -x 'select count(*) from <tablename>' ); echo $countvalue while... (2 Replies)
Discussion started by: baskivs
2 Replies

8. Shell Programming and Scripting

Connect status of db2 in Unix shell script

Hi I am trying to connect to db2 database from Unix shell script (k shell) I need to catch the status of connect whether it is succesful or not. ---------------------------------------------------------- # Read login credentials for db2 tput clear echo "Please enter your Userid:\c"... (3 Replies)
Discussion started by: mKarri
3 Replies

9. Shell Programming and Scripting

need help with UNIX, awk and DB2

Hi i am working on a script which takes a parameter file as input . this parameter file is having SQL statements. I am fetching column names from the output of SQL file using following code: while read Record1 do SQLQuery=`echo $Record1 | awk '{printf $0 }'` ... (2 Replies)
Discussion started by: manmeet
2 Replies

10. Red Hat

Installing RedHat 8.0 onto Dell PowerEdge SC1425 - hdc: status error: status = 0x58

I have successfully installed RedHat 8.0 onto a Dell PowerEdge SC1425 today. This server has two SATA hard drives, and an IDE DVD-ROM drive. Using the following kernel parameters, i successfully installed across both hard drives from CD: ide0=0x1f0,0x3f6,14 vga=791 resolution=1024x768 expert... (5 Replies)
Discussion started by: fishsponge
5 Replies
Login or Register to Ask a Question