Need to capture error of sybase isql in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to capture error of sybase isql in unix
# 1  
Old 01-04-2012
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 that it failed , but I am not getting any error msg. I dont know how to put error msg.

pls help me out.
Code:
retu_statu=`$SYBASE/OCS-15_0/bin/isql -S$DSQUERY -U$AAAUSER -P$AAAUSERPWD <<-END_SQL | grep "ERRORLEVEL" | cut -d ";" -f 2 
use $AAAREPDB
truncate table $AAAREPDB..CTF_EXTRACT_PTF
go
END_SQL`

bcp $AAAREPDB..CTF_EXTRACT_PTF in /oams/w_ctcb/ctcb2ta/data_extract/${BatchScript}.$$.out -U$AAAUSERPWD -P$AAAUSERPWD -S$DSQUERY -f portfolio.fmt -Y -F

    
err_code=$?
    if [[ $err_code != 0 ]]; then
        echo "ERROR: Data Loading failed!!!\n\n\n"
        exit 255
    fi

retu_statu=`$SYBASE/OCS-15_0/bin/isql -S$DSQUERY -U$USER -P$USERPWD <<-END_SQL | grep "ERRORLEVEL" | cut -d ";" -f 2 
use $AAAREPDB

insert into $REPDB..uob_dwh_portfolio
select *,getdate) from $REPDB..CTF_EXTRACT_PTF

select 'ERRORLEVEL',';',@@error,';'
go


END_SQL`

I am not getting any error Problem in query is Getdate()
It should give me error

---------- Post updated 01-05-12 at 09:21 AM ---------- Previous update was 01-04-12 at 05:06 PM ----------

any sollution

Last edited by zaxxon; 01-04-2012 at 05:08 AM.. Reason: "awaiting your replies" is similar as "urgent". removed that - I guess you don't want to post it again and again.
# 2  
Old 01-05-2012
What shell are you using? You should compare integers using -ne operator, not !=.
Also, echo the err_code, so that you see what is the value.

Code:
err_code=$? 
echo err_code $err_code
if [[ $err_code -ne 0 ]]; then    
  echo "ERROR: Data Loading failed!!!\n\n\n" 
  exit 255
fi

How is this script run? Is it run from terminal?


EDIT: On a second look, you say the problem is in the insert, but you are not checking how did that command exit. You are checking 'bcp' exit status.
So what you probably want, is get the $? of insert command as well.

It seems that a function could come handy:
Code:
function checkErr {
       if [[ $? -ne 0 ]] ; then
       echo "ERROR in $1" >&2
}

#your script contents here:
bcp .....
checkErr "bcp command"

insert ....
checkErr "insert command"


Last edited by mirni; 01-05-2012 at 12:17 AM..
# 3  
Old 01-05-2012
Its a ksh, running in unix server.
# 4  
Old 01-06-2012
Quote:
Originally Posted by mirni
What shell are you using? You should compare integers using -ne operator, not !=.
Also, echo the err_code, so that you see what is the value.

Code:
err_code=$? 
echo err_code $err_code
if [[ $err_code -ne 0 ]]; then    
  echo "ERROR: Data Loading failed!!!\n\n\n" 
  exit 255
fi

How is this script run? Is it run from terminal?


EDIT: On a second look, you say the problem is in the insert, but you are not checking how did that command exit. You are checking 'bcp' exit status.
So what you probably want, is get the $? of insert command as well.

It seems that a function could come handy:
Code:
function checkErr {
       if [[ $? -ne 0 ]] ; then
       echo "ERROR in $1" >&2
}

#your script contents here:
bcp .....
checkErr "bcp command"

insert ....
checkErr "insert command"



sorry I didnt Get you...

actually problem is in Insert Statement so I want it will show the error or write it in some file, when BCP has some problem It shows me error data not loaded , but i dont know how its showing this

---------- Post updated at 06:04 PM ---------- Previous update was at 06:00 PM ----------

How I can write checkerror in Isql
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Isql and If Exist syntax error in UNIX script

Hello Everyone, Coming again for your help to solve the below error: In a script, i had created a temp table (Temp_table) and loaded the data in it using bcp command (performed successfully) and I wanted to move it to the preferred table (called Main_table) for further use. hence I have added... (7 Replies)
Discussion started by: Suresh
7 Replies

2. Shell Programming and Scripting

Isql syntax error in UNIX script

Hello Everyone, Coming again for your help to solve the below error: In a script, i had created a temp table (Temp_table) and loaded the data in it using bcp command (performed successfully) and I wanted to move it to the preferred table (called Main_table) for further use. hence I have added... (1 Reply)
Discussion started by: Suresh
1 Replies

3. Shell Programming and Scripting

Error in Sybase connectivity via UNIX

Helo Experts, I have an issue in connecting to sybase from UNIX. PFB, my code : #!/bin/ksh ############################################################################### # # Filename: docflo_split.sh # # Description:docflo_split.sh WrapperScript splits the temporary file... (1 Reply)
Discussion started by: Nits
1 Replies

4. Shell Programming and Scripting

How to assign value from isql to UNIX variable

I want output to be assigned to UNIX variables echo "Enter RRS ID: " read rrs isql -SPROD_DDS -USYBUSER -PSYBPASS -b -osfg.out << EOF use sip go set nocount on select issuerId, legalStructTxt, productName, issuerName from sf_product where rrsId = $rrs go EOF (1 Reply)
Discussion started by: JayDoshi
1 Replies

5. Shell Programming and Scripting

Sybase isql writing spaces to file

I'm running isql in sybase on a Linux box to read a table, and write the contents to a file. It needs to be a nice comma delimited file for input into another system. It reads the DB fine and writes the file. However, I have two issues. 1) I don't want the line width to be limited in any... (2 Replies)
Discussion started by: Cynthia
2 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. Shell Programming and Scripting

How do i access sybase using isql and how do i get result set in perl script?

Hi, How do i get result set in perl script using isql while connecting sybase server. I have a perl script which connected to sybase and get the result set. but i wanted to get the result set. How do i get the result set in perl script not unix shell script.. $server ="ServerName"; open... (1 Reply)
Discussion started by: solo123
1 Replies

8. Shell Programming and Scripting

unix capture oracle function error

Hi, I want to execute an oracle function from unix script so for that I created a sample oracle function as below: create or replace function test_fn(test_date out varchar2) RETURN varchar2 IS BEGIN select to_char(sysdate,'DD-MON-YY') into test_date from dual; return test_date;... (5 Replies)
Discussion started by: dips_ag
5 Replies

9. Shell Programming and Scripting

Isql query in unix shell

Hi i want write a script for list of sysbase are having access or open. then i wrote like: USER="abc" PASS="xyz" SERVER="SCCS" DB="blue" WORK_DIR="/usr/home/ramakrishna" set -x isql -U${USER} -P${PASS} -S${SERVER}<<EOF>$WORK_DIR/output.log go use blue (database name) go use... (0 Replies)
Discussion started by: koti_rama
0 Replies

10. Shell Programming and Scripting

how to connect to sybase from Unix(AIX)

I have a script given below so can anyone explain me what it does? echo "use $DSQUERY\n go\n insert into ff.SmartCareLogin (username, password, userrole, fullname) values ('$1', '$1', '$2', '$3') go"|isql -Uff -P what is the use of $DSQUERY and go. When i am firiing isql command... (0 Replies)
Discussion started by: sachin.gangadha
0 Replies
Login or Register to Ask a Question