database instance Error capture


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting database instance Error capture
# 1  
Old 11-03-2010
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:

Code:
Msg 937, Level 14, State 1:
Server 'UAT_SRVR10':
Database 'test2' is unavailable. It is undergoing LOAD DATABASE.

Msg 4001, Level 11, State 1:
Server 'UAT_SRVR10':
Cannot open default database 'test2'.

Msg 208, Level 16, State 1:
Server 'UAT_SRVR10', Line 1:
TST_TABLE not found. Specify owner.objectname or use sp_help to check whether
the object exists (sp_help may produce lots of output).


MY SCRIPT:
Code:
isql -U${dbuid} -P${dbpwd} -S${dbsrv} -w5000 << EOF >> outfile
select * from the testtable where testargs='zombie'
go
exit

EOF
if [[ $? != 0 ]]
then
echo "`date` Error has occured.  Database is not available !! >>logfile
echo "`date` ABORTING  ===================================" >>logfile
echo " kill my script if the above error generated !!!"
 exit  11
fi

echo " DB connection met and continue to do the rest of the script"


System: SunOS 5.8 Generic_117350-53 sun4u sparc SUNW,Netra-T12
Database: Sybase
# 2  
Old 11-03-2010
Well, first, put the password on the first line of input stream.

You can grep -E various patterns to find errors in the error log.

I like to do something like this to separate the data from everything else (and you can add other processing in sed):
Code:
echo "$DB_PASSWD
select 'dAtA' as X, * from tablex . . . .
go' | isql -s'|' . . . 2>&1 | sed '
  s/^dAtA|//
  t d
  /^Password: $/d
  /^$/d
  /^|x   |/d
  /^|-[-|]*-|$/d
  b
  :d
  w '$data_file'
  d
 ' >>$log_file

# 3  
Old 11-03-2010
thanks for your response Smilie sed always gives me the buzz lol...
Okay just a bit confused where echo "$DB_PASSWD followed by the select..
Trying to understand since i'm just selecting for now..but i will be running delete along with other selects in this script..not sure how to modify my script along with sybase error capture and what you are trying to explain. if you don't mind elaborating a bit please Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error while sudo to instance via bash script

Team , I am trying to sudo to instnace using a shell script .In out put i am getting this error for every line ...I am running this script as root .. sudo su - userid -i db2 "command " Error /etc/profile: shopt: not found how can we overcome this error ? Can someone help on... (1 Reply)
Discussion started by: rocking77
1 Replies

2. Shell Programming and Scripting

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 if then echo "Actual count between... (3 Replies)
Discussion started by: karthik adiga
3 Replies

3. UNIX for Dummies Questions & Answers

Looking for first instance of an error in explorer log

Hi How to see the first instance of an error in explorer log ? In this case I want to know the first time error "SCSI transport failed" was populated in messages Thanks Amani (2 Replies)
Discussion started by: amani
2 Replies

4. Shell Programming and Scripting

Capture a database val and use in script

Hello, sorry if this has been asked before, I couldn't find what I was looking for. I know how to connect to Oracle and execute stored procedures from a shell script, but what I would like to do is return a value from a table and use it in my script. For Example, If I had a table Called... (1 Reply)
Discussion started by: mode09
1 Replies

5. Solaris

Getting error while trying to create a Solaris boot instance

I issue the following command to create a boot instance from an active boot instance on solaris 11.1. beadm create -a -d "Oracle x86 64 BIT Solaris SunOS Rel 5.11 Ver 11.1 10/2012 Enable SSH " OraSolBcp I get the following error below;- be_mount_callback: failed to mount dataset... (5 Replies)
Discussion started by: Tenyhwa
5 Replies

6. 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

7. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

8. UNIX for Dummies Questions & Answers

Howto capture data from rs232port andpull data into oracle database-9i automatically

Hi, i willbe very much grateful to u if u help me out.. if i simply connect pbx machine to printer by serial port RS232 then we find this view: But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)
Discussion started by: boss
1 Replies

9. 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

10. UNIX for Advanced & Expert Users

Printer Error(the Object Instance Test Does Not Exist)

Hello, i need some help about how to set up a high velocity impact printer in UNIX SCO 5.05, this printer is attached with a parallel port in a PC(host), the host use tunemul to access unix.(this reference is just to ask you if this is a local or remote connection, just to be sure), so, i... (2 Replies)
Discussion started by: jav_v
2 Replies
Login or Register to Ask a Question