db connection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting db connection
# 1  
Old 05-29-2011
db connection

Hi,
I'm trying to write a script which will run a select on db.
Code:
#!/usr/bin/ksh
SQL_INPUT_FILE=file_name.sql
SQL_OUTPUT_FILE=output.txt
MANPATH=/usr/share/man:/opt/SUNWspro/man:/usr/local/man
PATH=/opt/oracle/product/11g/bin:/sbin:/usr/sbin:/usr/ccs/bin:/usr/bin:/sbin:/opt/oracle/product/11g/OPatch:/usr/local/bin:/u
sr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/bin
NLS_LANG=AMERICAN_AMERICA.UTF8
ORACLE_SID=ora11g
ORACLE_TERM=xterm
ORACLE_HOME=/home/oracle/product/11g
export ORACLE_SID
export NLS_LANG
export ORACLE_HOME
export PATH
export ORACLE_TERM

/home/oracle/product/11g/bin/sqlplus user/pass@ora11g < $SQL_INPUT_FILE  > $SQL_OUTPUT_FILE

however the output file turns out such that:
Code:
SQL*Plus: Release 11.1.0.7.0 - Production on Sun May 29 23:43:14 2011

Copyright (c) 1982, 2008, Oracle. All rights reserved.

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


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

Can you help me?

Last edited by Scott; 05-29-2011 at 06:14 PM.. Reason: Code tags, please...
# 2  
Old 05-30-2011
First try
Code:
tnsping ora11g

It this works it should work for sqlplus also. Otherwise listener might not be running. If no problem in listener. Are you sure you are giving $user/$pass rather than user/pass in the sqlplus?
# 3  
Old 05-30-2011
Quote:
Originally Posted by ozum
...
however the output file turns out such that:
Code:
SQL*Plus: Release 11.1.0.7.0 - Production on Sun May 29 23:43:14 2011

Copyright (c) 1982, 2008, Oracle. All rights reserved.

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


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

Can you help me?
If tnsping does not work also check the local tnsnames.ora file if there is an entry for ora11g. Usually the file can be found at $ORACLE_HOME/network/admin.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote connection

How can we connect to remote computers with a bash script.? (1 Reply)
Discussion started by: diw10
1 Replies

2. UNIX for Dummies Questions & Answers

DB connection

hi Im unable to find how this script in conencting to DB and which DB and job is scheduled in TWS to run this script. Any sugggestion where to look for or how to get information. please find below part of script for DB conenction. ##### SET VARIABLES ################## rundate=`date... (1 Reply)
Discussion started by: saif2825
1 Replies

3. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

4. AIX

IP connection

Hi, I have a server AIX 5.3 Few people have the root password and somebody used the root login to erase a file (command rm in the .sh_history of root). :mad: I would like to know if a file exist with what ip address has been connected. I want to find the guilty!!! :D Thanks guys (2 Replies)
Discussion started by: Castelior
2 Replies

5. Solaris

PC-X connection

Hi all, I have just installed SunOS 10 at the first PC and exceed (pc-x server) at the second. I'm trying to connect to the first pc via exceed softvare. After entering login and pass, the exceed window immidiate close without any errors (if CDE or JDS has been chosen). Via exceed working just... (0 Replies)
Discussion started by: Marauder62
0 Replies

6. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

7. UNIX for Advanced & Expert Users

Connection reset by peer..closing connection

Hello I'm facing the above problem while doing a performance run. I've a script which I'm launching from my windows desktop using mozilla. The script will invoke backend action on a Solaris host which in turn feeds the records to a driver located on a linux box(Cent OS). What's happening is... (1 Reply)
Discussion started by: subramanyab
1 Replies

8. UNIX for Dummies Questions & Answers

ssh_exchange_identification: Connection closed by remote host Connection closed

Hi Everyone, Good day. Scenario: 2 unix servers -- A (SunOS) and B (AIX) I have an ftp script to sftp 30 files from A to B which happen almost instantaneously i.e 30 sftp's happen at the same time. Some of these sftp's fail with the following error: ssh_exchange_identification: Connection... (1 Reply)
Discussion started by: jeevan_fimare
1 Replies

9. IP Networking

HOw to start a connection?

Hi, I understand assignment qns are not allowed. However, I need major help.. please teach me how to write a tcp/ip programme using C, wad are the websites that i can refer to? wad are the codes required for it? I have never done tcp/ip configurations before, and never learnt C before,... (13 Replies)
Discussion started by: microuniz
13 Replies

10. Cybersecurity

FTP Connection

I just started a new job and inherited a Fedora core 3 server. I wanted to open the ftp ports and I wanted to verify this code before I mess things up. From my reading the two lines below should allow ftp access can anyone confirm my attempt. iptables -A INPUT -p tcp - sport 21 -m state - state... (0 Replies)
Discussion started by: mungaz
0 Replies
Login or Register to Ask a Question