Shell script verify connection to Oracle if not successful


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script verify connection to Oracle if not successful
# 1  
Old 03-26-2019
Shell script verify connection to Oracle if not successful

i have a script that connects to the oracle database and executes the query statements. it works fine and i would like to add some message to check if the connection to oracle is not successful.

basically this is the code snippet:
Code:
#!/bin/sh
...
...
...
sqlplus -s username/password@dbName <<EOF > script.log
...
...
...
EOF
exit

how do I add it on the script?

thank you.
# 2  
Old 03-27-2019
You need to create a script or wrapper that expects a return status from the server and process the return status.

More specifically, you can use:

Code:
WHENEVER SQLERROR EXIT SQL.SQLCODE
WHENEVER OSERROR EXIT

For example:

Code:
WHENEVER SQLERROR EXIT SQL.SQLCODE
begin
  SELECT COLUMN_DOES_NOT_EXIST FROM DUAL;
END;
/

And for OS errors:

Code:
WHENEVER OSERROR EXIT FAILURE
START no_such_file

Check out the reference material for more details:

SQL*Plus Command Reference
# 3  
Old 03-27-2019
This topic has been covered umpteen times in these fora. Use the search function, or look into the links given at the lower left of this page under "More UNIX and Linux Forum Topics You Might Find Helpful".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script is hanging up every time even after it's successful

We are using a korn shell script which is meant to trigger a Oracle job to load the data from a flat file to an Oracle database . Also the same script addresses the following tasks also like triggering a SFTP job to pick the file from one path to the target location and checking the same with... (6 Replies)
Discussion started by: senmng
6 Replies

2. Shell Programming and Scripting

How to check the status of sftp connection is successful or not in Linux?

Hi All, We are working on linux with putty terminal for file transferring using SFTP server... here we want to know /We have Urgent Requirement If SFTP connection is successfull then we should get .txt log file in target locaton as "Success/Failure" Please provide batch script for above... (7 Replies)
Discussion started by: sravanreddy
7 Replies

3. UNIX for Dummies Questions & Answers

How to fix connection to Oracle database through shell script?

I have a question regarding how to connect to Oracle Database through shell script. 1. If I want call a stored procedure on Linux server as this, it works. $sqlplus /nolog SQL*Plus: Release 12.1.0.2.0 Production on Fri Jun 12 14:49:49 2015 Copyright (c) 1982, 2014, Oracle. All rights... (2 Replies)
Discussion started by: duke0001
2 Replies

4. Shell Programming and Scripting

How to setup Oracle connection inside shell script?

Hi, We have Oracle Connection parameters set up in file name "TESTDB" at location /abc/etc.When I try to run my shell script it does not connect to Oracle database. Please let me know how "TESTDB" file can be called inside script. ####################### Setting the directories... (2 Replies)
Discussion started by: sandy162
2 Replies

5. Shell Programming and Scripting

How the user will provide the parameters for Oracle db connection in a shell script?

I'm new into unix. My question: is possible to write a shell script which will ask for the ORACLE_HOME, ORACLE_SID, USERNAME, PASSWORD to connect to Oracle db. In generally we have to set the ORACLE_HOME in .profile file. And after putting the 'sqlplus' command it asks for the username &... (6 Replies)
Discussion started by: priya001
6 Replies

6. Shell Programming and Scripting

Verifying oracle connection from shell script

Hi, Oracle 9.2 Solaris 10 From the shell script ........How can we verify whether oracle connection is successful or not ? Shell script will prompt the user to enter the oracle schema username, password and tns name. So, *how to verify whether oracle connection has been established or... (14 Replies)
Discussion started by: milink
14 Replies

7. UNIX for Advanced & Expert Users

Connection closing immediatly after successful login

When ssh'ing into certain Unix boxes I'm seeing two errors that appear immediately after entering the password I've never seen. After the error message is displayed the connection closes immediately. The first is “/bin/ksh: Not owner” after which the connection is closed. And, “Read from remote... (2 Replies)
Discussion started by: twk
2 Replies

8. Shell Programming and Scripting

oracle connection from shell script

Hi, For connecting to oracle my script is using the command sqlplus username/password@db_instance_name.For this to work i am setting ORACLE_HOME,TNS_ADMIN and ORACLE_SID in a seperate script.My question is,could we make a connection to oracle just by the command sqlplus... (4 Replies)
Discussion started by: DILEEP410
4 Replies

9. Solaris

Can before and after snapshots be used to verify successful filesystem restoration?

Hello Guys, Can before and after snapshots be used to verify successful filesystem restoration? snapshots will be created using fssnaps and restoration is thru legato restore? Any ideas on this? or any other ways I could verify that restoration is good? Regards (0 Replies)
Discussion started by: MarkyBoy
0 Replies

10. Shell Programming and Scripting

shell script- oracle connection problem

Hi all, I am having problem with a shell script. I have a couple of csv files. The shell script will do some operation on them, create a sql file which will then be called by sqlplus. The problem is to gracefully exit sqlplus at the end of every operation as I do not want to hang on to the... (4 Replies)
Discussion started by: nattynatty
4 Replies
Login or Register to Ask a Question