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:

#!/bin/sh
...
...
...
sqlplus -s username/password@dbName <<EOF > script.log
...
...
...
EOF
exit

how do I add it on the script?

thank you.

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:

WHENEVER SQLERROR EXIT SQL.SQLCODE
WHENEVER OSERROR EXIT

For example:

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

And for OS errors:

WHENEVER OSERROR EXIT FAILURE
START no_such_file

Check out the reference material for more details:

SQL*Plus Command Reference

This topic has been covered umpteen times in these forums. 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".