Sudheer Inamana
Sudheer Inamana

Reputation: 25

Connecting db using shell script by passing db credentials from shell

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.

Upvotes: 1

Views: 2172

Answers (2)

Sylvain Leroux
Sylvain Leroux

Reputation: 52000

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]

Upvotes: 1

podwysoc
podwysoc

Reputation: 41

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

dbcheck.sh username/password@database

Have you read the correct sqlplus syntax?

Upvotes: 0

Related Questions