SQLPLUS in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SQLPLUS in script
# 1  
Old 03-06-2006
SQLPLUS in script

I have a script that passes a parameter to the sqlplus command that looks like the following:


#!/bin/sh

TARGET_SID=$1
AUXILIARY_SID=$2
sqlplus 'sys@$AUXILIARY_SID as sysdba' @shutdown.sql

I keep getting the following error:
ERROR:
ORA-12154: TNS:could not resolve service name
HOWEVER, I have my sid defined in the tnsnames.ora AND if I take out the parameter $AUXILIARY_SID and put in the actual sid name (PPRD) it works fine. Any Ideas?

Thanks!
Rhonda Nichols
# 2  
Old 03-06-2006
Use double quotes rather than single quotes.
# 3  
Old 03-06-2006
Thanks. I never thought of somthing so simple. One more thing. I am trying to pass the pswd as a parameter so that it doesn't so up during ps -ef as follows:


PSWD=***** (where stars are my password)
sqlplus "sys@$AUXILIARY_SID as sysdba" @shutdown.sql <$PSWD


but of course this doesn't work. Can this be done? What am I doing wrong?

-Rhonda
# 4  
Old 03-06-2006
Sorry, I had a DUH moment.

I just did this:

sqlplus "sys/$PSWD@$AUXILIARY_SID as sysdba" @shutdown.sql

I think this will work

THANKS!
# 5  
Old 03-06-2006
An alternative is:
Code:
echo $PSWD | sqlplus "sys@$AUXILIARY_SID as sysdba" @shutdown.sql

or you can use a named pipe:
Code:
mknod p sysdba_logon.sql
echo "connect sys/$PSWD@$AUXILIARY_SID as sysdba" > connect.sql &
sqlplus <<-EOF
@connect.sql
@shutdown.sql
EOF
rm connect.sql

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SQLPLUS calling Via Script

Hello All, Could you please help me if i am doing anything wrong in below script, especially the sqlplus part performance wise or anything else i could improvise in the script. Thank you. #!/bin/ksh ## Batch Obj Id MP_BCH_OBJ_ID=$1 PASS=$2 partition=$3 ## script dir... (6 Replies)
Discussion started by: Ariean
6 Replies

2. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

3. Shell Programming and Scripting

Sqlplus in shell script

Hi All, Please let me know what i am missing in the following code (part of my script) Schemas=(AWQM WFCONTROLLER PROVCO PRISM) for s in "${Schemas}" do sch="${s}_$tol" if || ;then echo "This is AD or TD region" sqlplus -s $sch/$tpwd@$ttns <<EOF... (7 Replies)
Discussion started by: pvmanikandan
7 Replies

4. Shell Programming and Scripting

sqlplus in shell script

Hi When I use sqlplus in shell script, I get sqlplus: command not found. ORACLE_HOME is not set. How to set ORACLE_HOME in unix? Thanks (3 Replies)
Discussion started by: vinoth_kumar
3 Replies

5. UNIX for Dummies Questions & Answers

sqlplus script out param

For starters, I have read the forums from top to bottom and cannot find a solution to this particular scenario. Just finished up two hours or scouring the archives. Here is my question which has been asked numerous times before but never fully explained for this particular solution: How do I pass a... (2 Replies)
Discussion started by: jwil0m0
2 Replies

6. Shell Programming and Scripting

SQLPLUS within shell script

Hi I want to connect to the Oracle database using a username/password and get back the query result(a numeric value) in a variable, which I can then compare using a conditional. Can anybody help me with this. Thanks Gaurav (4 Replies)
Discussion started by: gaurav_1711
4 Replies

7. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

8. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies

9. UNIX for Dummies Questions & Answers

Shell Script And SQLPLUS

i'm having real problems retrieving the returncode of my sqlplus-call. I found a lot of informations on the net, but havn't been able to get it running so far, so now i ask for some help ;) I do start the sqlplus out of my shell script with the parameters stored in the proc_clips.sql, which is... (6 Replies)
Discussion started by: maco_home
6 Replies

10. Shell Programming and Scripting

connect to sqlplus in a script

Hi, I want to write a script, in which I will connect to sqlplus and do a quary and then exit sqlplus user/pwd@database select count(*) from table exit. and write the result in a log file. How to write it ? Many thanks before. (1 Reply)
Discussion started by: big123456
1 Replies
Login or Register to Ask a Question