# Shell script verify connection to Oracle if not successful

**URL:** <https://community.unix.com/t/shell-script-verify-connection-to-oracle-if-not-successful/375239>\
**Category:** Shell Programming and Scripting\
**Created:** [March 26, 2019, 3:39pm UTC](https://community.unix.com/t/shell-script-verify-connection-to-oracle-if-not-successful/375239 "2019-03-26T15:39:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wtolentino](https://community.unix.com/letter_avatar/wtolentino/32/6_449c533f586939b6e5f246632a46421f.png) [@wtolentino](https://community.unix.com/u/wtolentino)\
**Post date:** [March 26, 2019, 3:39pm UTC](https://community.unix.com/t/shell-script-verify-connection-to-oracle-if-not-successful/375239/1 "2019-03-26T15:39:36Z")

</div>

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:

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

```

how do I add it on the script?

thank you.

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [March 26, 2019, 11:59pm UTC](https://community.unix.com/t/shell-script-verify-connection-to-oracle-if-not-successful/375239/2 "2019-03-26T23:59:47Z")

</div>

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:

```plaintext
WHENEVER SQLERROR EXIT SQL.SQLCODE
WHENEVER OSERROR EXIT

```

For example:

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

```

And for OS errors:

```plaintext
WHENEVER OSERROR EXIT FAILURE
START no_such_file

```

Check out the reference material for more details:

[SQL\*Plus Command Reference](https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12052.htm)

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [March 27, 2019, 5:04am UTC](https://community.unix.com/t/shell-script-verify-connection-to-oracle-if-not-successful/375239/3 "2019-03-27T05:04:18Z")

</div>

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