Not able to connect to Oracle server from shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to connect to Oracle server from shell script
# 1  
Old 11-02-2018
Not able to connect to Oracle server from shell script

Hi,

I am facing an issue in connecting to database from Linux shell script. Here is my code

Code:
export ORACLE_BASE=xxx
export ORACLE_SID=xxx
export ORACLE_HOME=xxxx

DB_PATH=xxx/'yyy@yy'


UserId=`sqlplus -s $DB_PATH  <<EOF
set head off feedback off
select max(USER_ID)+1 from USERS;
exit;
EOF`
echo "User ID is - $UserId"


When I run the script, I am getting the below error.
Code:
User ID is - ERROR:
ORA-12545: Connect failed because target host or object does not exist

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


I tried with ping and telnet to the DB Server from Linux server then connection was success.
I verified tnsnames.ora and tried by giving IP address of host etc but did not work. Can anyone please let me know any solution for this?

Last edited by vgersh99; 11-02-2018 at 12:57 PM..
# 2  
Old 11-02-2018
Have you tried: tnsping ${ORACLE_SID} ?
Also:
Code:
UserId=$(sqlplus -s $DB_PATH  <<EOF 
set head off feedback off 
select max(USER_ID)+1 from USERS;
exit; 
EOF
)

# 3  
Old 11-02-2018
How can you connect to a database without a userid and password for the database?

Your script does not seem to perform the basic connection call with the right parameters; and that is also what the error message indicates.
# 4  
Old 11-02-2018
Thanks for your suggestions.
@vgersh99
Hi, I have tried with the code provided by you but same error is coming. I also tried to tnsping but getting the below error.
-bash: tnsping: command not found.
Please suggest.
@Neo
Hi, I have given userid and password in the variable DB_PATH and used the same. Since there are special characters in the password I enclosed in parenthesis.
# 5  
Old 11-02-2018
tnsping lives in the same path as sqlplus
# 6  
Old 11-02-2018
I tried from oracle home directory and getting the below error.

Code:
TNS Ping Utility for Linux: Version 11.2.0.3.0 

Used parameter files:
/opt/app/oracle/product/11.2.0/network/admin/sqlnet.ora
TNS-03505: Failed to resolve name


Last edited by vgersh99; 11-02-2018 at 02:57 PM.. Reason: Once again - please start using code tags!
# 7  
Old 11-02-2018
Quote:
Originally Posted by yuvi
I tried from oracle home directory and getting the below error.

Code:
TNS Ping Utility for Linux: Version 11.2.0.3.0 

Used parameter files:
/opt/app/oracle/product/11.2.0/network/admin/sqlnet.ora
TNS-03505: Failed to resolve name

there you have it - your sqlnet.ora is not configured (correctly?) for the SID you're trying to tnsping.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to connect from one server to other

Dear Experts, I am new to the shell scripting. I am looking for a shell script to connect to one Unix/Linux server1 to other Unix/Linux server2 and trigger a SAP Event in that server2 (Which will trigger a job in SAP). Is this possible to connect from one server to the other server securely... (7 Replies)
Discussion started by: Venu V Reddy
7 Replies

2. Shell Programming and Scripting

How to connect to Oracle database using shell script?

Hi All, I am newbie to unix shell scripting. I want to connect to oracle database using shell script. I know how to connect DB using user name and password but my question is if my password is having '@' sign then how to connect. I have tried like below, cnt=`sqlplus -s /nolog << EOFSQL ... (3 Replies)
Discussion started by: pmotewar
3 Replies

3. Shell Programming and Scripting

Shell Script to connect to the oracle database

Hi Unix Gurus, I have a requirement to write a script, Oracle DB gets referesh every 6hrs, hence we need write a script to connect to the database , if it connects it should generate a file to proceed the next job application or when an error when connectiong to DB it should not generate any... (8 Replies)
Discussion started by: bshivali
8 Replies

4. Shell Programming and Scripting

Connect Oracle using shell script at run time

Hi all, I am a newbie.....am jus trying to connect to oracle thro a script, but not thro giving the username/password@server_name directly like `$ORACLE_HOME/bin/sqlplus username/password@server_name In the above line, once it is connected to Oracle, it shud ask me the username and password... (4 Replies)
Discussion started by: kritibalu
4 Replies

5. Shell Programming and Scripting

Need help in writing a shell Script to connect to oracle instance

Please help me in writing a shell script which connects to a Oracle instance and tables to get the required information...:wall: (1 Reply)
Discussion started by: Dpu
1 Replies

6. Shell Programming and Scripting

connect to SQL server from shell script

Hi all, I need to connect to SQL server from shell script. Then need to execute queries from shell script as below 1. To compare values of an array with SQL table's entry. I am using solaris-5.1 to run shell script and want to connect to SQL-5.1 which is installed on SantOS. Kindly let... (3 Replies)
Discussion started by: amitbhelave
3 Replies

7. Solaris

connect to SQL server from shell script

Hi all, I need to connect to SQL server from shell script. Then need to execute queries from shell script as below 1. To compare values of an array with SQL table's entry. Kindly let me know on how to do this Thanks, Double post. Continue here (0 Replies)
Discussion started by: amitbhelave
0 Replies

8. Shell Programming and Scripting

connect to SQL server from shell script

Hi all, I need to connect to SQL server from shell script. Then need to execute queries from shell script. Kindly let me know on how to do this Thanks, Ananthi.U (1 Reply)
Discussion started by: ananthi_ku
1 Replies

9. Shell Programming and Scripting

Connect to oracle db using shell script

Hi, I want to connect to oracle db using unix shell script. And i want to retrieve data from db through shell script. Please help me as soon as possible. Thanks, J.P. Das (1 Reply)
Discussion started by: jyotidas
1 Replies

10. Programming

How to write a shell script to connect to another server?

Hello friends I want to write a script in which I will connect to my friends network. I want to use SSH. Even they can use the script to log into my network and copy files. ssh user@hostname command I know the following command will help me to log into Google's servers and see all the... (12 Replies)
Discussion started by: Angelo
12 Replies
Login or Register to Ask a Question