Error during running sqlplus command from shell script in Solaris


 
Thread Tools Search this Thread
Operating Systems Solaris Error during running sqlplus command from shell script in Solaris
# 1  
Old 05-28-2013
Error during running sqlplus command from shell script in Solaris

I am using following code to connect to oracle database from solaris shell script. which will try thrice to connect the database ...at the 4rth atempt it will exir=t.

Code:
 
count=0
while [ $count -lt 3 ]; do
sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile
WHENEVER OSERROR EXIT 9;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
DBMS_OUTPUT.put_line('Connected to db');
EOF
conn_code=$?
if [ $conn_code != 0 ];then
count=`expr $count + 1`
else
break
fi
done
if [ $count = 2 ];then
logfn "Database connectivity is not working fine....check the username/password"
exit 0;
fi
logfn "Database connectivity is working fine"

But i am getting below error.

Code:
 
Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
where <option> ::= -H | -V | [ [-C <v>] [-L] [-M <o>] [-R <n>] [-S] ]
      <logon>  ::= <username>[/<password>][@<connect_identifier>] | / | /NOLOG
      <start>  ::= @<URL>|<filename>[.<ext>] [<parameter> ...]
        "-H" displays the SQL*Plus version banner and usage syntax
        "-V" displays the SQL*Plus version banner
        "-C" sets SQL*Plus compatibility version <v>
        "-L" attempts log on just once
        "-M <o>" uses HTML markup options <o>
        "-R <n>" uses restricted mode <n>
        "-S" uses silent mode

Pls let me know What is wrong here?
# 2  
Old 05-28-2013
Hi Millan,

Try examining what command you are sending...ie
Code:
echo trying to connect to dbSID with user: $username and password $password
sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile
WHENEVER OSERROR EXIT 9;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
DBMS_OUTPUT.put_line('Connected to db');
EOF

# 3  
Old 05-28-2013
There are so many errors in your code as written that I had to rewrite most of it.
Note: spaces around [ ] characters MUST be there, DBMS_OUTPUT only works from PL/SQL, etc.

PLEASE note the columns I put things in like the / character, please note spacing. I assumed logfn was a valid command on your machine - it is not on mine.

Code:
#!/bin/ksh

export logfile=t.log

count=0
while [ $count -lt 3 ]; do

     sqlplus -s $usrname/$password <<-EOF >> $logfile
     WHENEVER OSERROR EXIT 9;
     WHENEVER SQLERROR EXIT SQL.SQLCODE;
     SET SERVEROUT ON SIZE 1000000
     DECLARE
     BEGIN
     DBMS_OUTPUT.ENABLE(1000000);
     DBMS_OUTPUT.put_line('Connected to db');
     END;
/
EOF

 conn_code=$?
 if [ $conn_code -ne 0 ]; then
    count=`expr $count + 1`
 else
    break
 fi
done
if [ $count -eq 2 ]; then
  logfn "Database connectivity is not working fine....check the username/password"
  exit 0;
fi
logfn "Database connectivity is working fine"

# 4  
Old 05-28-2013
As Jim mentioned DBMS_OUTPUT package is useful for displaying PL/SQL debugging information.

For SQL*Plus, you can use PROMPT to display text on user's screen

Syntax:
Code:
PRO[MPT] [text]

# 5  
Old 05-28-2013
In my code , the error is giving while i am running sqlplus -s option in solaris...how to handle this for silent connection in solaris..i also tried with -S..but no luck..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Help required for Running SQLPLUS command from Bat file

Hello All, Good Afternoon. I am new to this platform and I need one small help regarding running a SQL file from Bat file. Below is what I am doing, 1. I placed the below command in one Bat file. start putty.exe -ssh user@host -pw pwd -m C:\2.txt 2. In 2.txt, I have below command. ... (3 Replies)
Discussion started by: PavanPatil
3 Replies

2. Shell Programming and Scripting

Running sqlplus for 5 DB in a shell

Hi all, on AIX 6.1 I want to run the following but for 5 DB. How should I do that ? Using FOR, WHILE ???? How ? export ORACLE_SID=DB1 sqlplus / as sysdba << EOF whenever sqlerror exit sql.sqlcode; whenever oserror exit FAILURE set define off set head off set feedback off set echo off... (1 Reply)
Discussion started by: big123456
1 Replies

3. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

4. Shell Programming and Scripting

Error while using sqlplus command inside 'if' condition in an unix shell script

Hi all, I am using the below given sqlplus command in my unix script to invoke a stored procedure which returns a value .It works fine. RET_CODE=$(/opt/oracle/product/10.2.0.4.CL/bin/sqlplus -S $USER/$PASSWD@$DB_NAME <<EOF EXEC MY_PKG.MY_SP (:COUNT); PRINT COUNT; commit; ... (6 Replies)
Discussion started by: Shri123
6 Replies

5. Shell Programming and Scripting

Running SQLPLUS Script in CRONTAB

Hi, Can someone please help me here with this one. This is my script: # more tosh.sh #!/usr/bin/ksh clear . /home/oracle/.profile echo "Good morning, world." export ORACLE_HOME=/u01/app/oracle/product/9.0.1 export PATH=$ORACLE_HOME/bin:/usr/local/bin export ORACLE_SID=xxxx ... (11 Replies)
Discussion started by: santoshpayal
11 Replies

6. Shell Programming and Scripting

URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 Replies

7. Shell Programming and Scripting

error running sqlplus from shell file

I am running a shell file following script on bash shell in solaris 10 ( echo abc@orcl echo abc echo "set feedback off" echo "truncate table SIndexDataTypeHst1_changes;" ) | sqlplus -s but getting the following error ERROR: ORA-01005: null password given; logon denied ... (3 Replies)
Discussion started by: mmunir
3 Replies

8. Shell Programming and Scripting

error in passing a variable to sqlplus from a shell script

hi, I am using a shell script from where i will be conecting to sqlplus.. i am having a problem in passing a variable to sqlplus query.. i will be assigning the variable in the unix environment..whenever i am trying to pass a variable having the contents greater than 2500 characters, i am... (3 Replies)
Discussion started by: kripssmart
3 Replies

9. Shell Programming and Scripting

Facing issue in Solaris OS in crontab for running shell script

Hello i have a shell script. it is running fine when i manually run at command prompt using following command ./script_file but while running shell script from crontab, it is giving error in each line. (2 Replies)
Discussion started by: mabrar
2 Replies

10. Shell Programming and Scripting

running shell script from sqlplus

I have a script which connects to different database servers using sqlplus. Is there a way by which I can run a shell command on that host from sqlplus? I know about 'host' command but it runs script on the local machine where the original script is running. Is there a way to run command on the... (9 Replies)
Discussion started by: dkr123
9 Replies
Login or Register to Ask a Question