1

Hi I am trying to connect my database using shell script and by passing the db credentials from shell. I am getting "ORA-12162: TNS:net service name is incorrectly specified". Please find the script below.

#!/bin/bash
DB_CREDENTIALS=$1

mkdir -p $PWD/logs

sqlplus -silent $DB_CREDENTIALS <<EOFSQL

set echo on
set timing on
set heading on
set feedback on
set linesize 5000
SET PAGESIZE 0
SET TRIMSPOOL ON


@teshscrpt.sql


EOFSQL

And the error is :

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon>  ::= <username>[/<password>][@<connect_identifier>] | /
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

Can somebody help me out kindly.

Thanks, sudhir.

2
  • And how do you call your script ? Commented Dec 23, 2014 at 12:13
  • I am trying to call my script from shell like "bash-4.2$ dbcheck.sh" Commented Dec 23, 2014 at 12:18

2 Answers 2

1

First, you should take the habit of quoting your variables:

#!/bin/bash
DB_CREDENTIALS="$1"                         # HERE

mkdir -p "$PWD"/logs                        # HERE

sqlplus -silent "$DB_CREDENTIALS" <<EOFSQL  # HERE

Then:

I am trying to call my script from shell like bash-4.2$ dbcheck.sh

Obviously, your script take the connection parameters as first argument. you should invoke it like that:

bash-4.2$ dbcheck.sh username/[email protected]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot Sylvalin Leroux.
0

You need to put correct credentials. Launch it like this:

dbcheck.sh username/password@database

Have you read the correct sqlplus syntax?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.