Verifying oracle connection from shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Verifying oracle connection from shell script
# 1  
Old 10-13-2010
Verifying oracle connection from shell script

Hi,

Oracle 9.2
Solaris 10

From the shell script ........How can we verify whether oracle connection is successful or not ?

Shell script will prompt the user to enter the oracle schema username, password and tns name.

So, *how to verify whether oracle connection has been established or not ??*

If user entered schema name & password is correct then proceed further else script will again prompt for schema user name & password.


With Regards
This User Gave Thanks to milink For This Post:
# 2  
Old 10-13-2010
Code:
#!/bin/ksh
# usage $1 = username  $2=pwd, assumes ORACLE_SID and TWO_TASK (if needed) are set 
test_conn()
{
     usr="$1"
     pwd="$2"
     sqlplus -s ${usr}/${pwd}  << EOF | tr -d '[:space:]'
     set feed off
     set head off
     set pages 0
     set verify off
     select 'ok' from dual;
     exit
EOF
}
oops=1
while [ $oops -eq 1]
do
  print 'Enter username: ';  read uname 
  print 'Password: ';  
  stty -echo
     read pass
  stty echo
  result=$(test_conn $uname $pass)
  if [ "$result" = "ok"]  then
     oops=0
  fi

start with that.

Last edited by jim mcnamara; 10-13-2010 at 11:54 AM..
# 3  
Old 10-13-2010
@jim mcnamara

Could you pls explain this piece of code. I guess this makes the given input (password) to be invisible..Kindly brief..

Code:
  stty -echo
     read pass
  stty echo

# 4  
Old 10-13-2010
# 5  
Old 10-13-2010
Hi,

Executed the script but getting the below error :

Code:
$ ./test_oracle_conn.sh
./test_oracle_conn.sh[18]: select: bad identifier

With Regards
# 6  
Old 10-13-2010
Quote:
Originally Posted by jim mcnamara
Code:
#!/bin/ksh
# usage $1 = username  $2=pwd, assumes ORACLE_SID and TWO_TASK (if needed) are set 
test_conn()
{
     usr="$1"
     pwd="$2"
     sqlplus -s ${usr}/${pwd}  << EOF | tr -d '[:space:]'
     set feed off
     set head off
     set pages 0
     set verify off
     select 'ok' from dual;
     exit
EOF
}
oops=1
while [ $oops -eq 1]
do
  print 'Enter username: ';  read uname 
  print 'Password: ';  
  stty -echo
     read pass
  stty echo
  result=$(test_conn $uname $pass)
  if [ "$result" = "ok"]  then
     oops=0
  fi

start with that.
You probably should catch or disable interrupts to the script while reading the password. If the user hits CTRL-C while the script is trying to read the password the TTY will be left in a non-echoing state.
# 7  
Old 10-13-2010
Hi,

On executing the script getting the below error :

Code:
$ ./test_oracle_conn.sh
./test_oracle_conn.sh: line 18: syntax error near unexpected token `from'
./test_oracle_conn.sh: line 18: `         select "ok" from dual;'

Sorry, I am new with shell script

With Regards

---------- Post updated at 05:10 PM ---------- Previous update was at 04:31 PM ----------

Hi,

I have done something like this :

Code:
printf "$FBOLD\nEnter username: $FREG"
read user_name
printf "$FBOLD\nEnter password: $FREG"
read password
printf "$FBOLD\nEnter TNS name: $FREG"
read tns

Code:
sqlplus $user_name/$password@$tns | echo "select 'ok' from dual;" > c:/tmp/check_conn.txt

But,
On checking file check_conn.txt, it contains select 'ok' from dual;

How to pass the output of the select statement in the output file ??

how it can be done ?

With Regards
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 verify connection to Oracle if not successful

i have a script that connects to the oracle database and executes the query statements. it works fine and i would like to add some message to check if the connection to oracle is not successful. basically this is the code snippet: #!/bin/sh ... ... ... sqlplus -s username/password@dbName... (2 Replies)
Discussion started by: wtolentino
2 Replies

2. Shell Programming and Scripting

Help! Shell Script for Wifi Connection

Hi, I am quite new to shell scripting and was wondering if it was possible to automatically enter the username and password fields to a wifi-access-router and then ping it. I have most trouble with entering the username and password fields. Is that even possible? Also, what do I do if the... (1 Reply)
Discussion started by: Xyn
1 Replies

3. Shell Programming and Scripting

Connection with Teradata through shell Script

Hi All, As we are using SQLPLUS command to connect Oracle Database in unix: Like below syntax: sqlplus username/password@dbname << EOI SET HEADING OFF SPOOL MAX_DATE_VAL.txt select max(LAST_UPDT_DATE) from source_defect; SPOOL OFF here the result is stored in... (0 Replies)
Discussion started by: Shilpi Gupta
0 Replies

4. UNIX for Dummies Questions & Answers

How to fix connection to Oracle database through shell script?

I have a question regarding how to connect to Oracle Database through shell script. 1. If I want call a stored procedure on Linux server as this, it works. $sqlplus /nolog SQL*Plus: Release 12.1.0.2.0 Production on Fri Jun 12 14:49:49 2015 Copyright (c) 1982, 2014, Oracle. All rights... (2 Replies)
Discussion started by: duke0001
2 Replies

5. Shell Programming and Scripting

How to setup Oracle connection inside shell script?

Hi, We have Oracle Connection parameters set up in file name "TESTDB" at location /abc/etc.When I try to run my shell script it does not connect to Oracle database. Please let me know how "TESTDB" file can be called inside script. ####################### Setting the directories... (2 Replies)
Discussion started by: sandy162
2 Replies

6. Shell Programming and Scripting

Verifying if a file exist (script shell)

Hello, This is my code: nb_lignes=`wc -l $1 | cut -d " " -f1` for i in $(seq $(($nb_lignes - 1)) ) do machine=`head $1 -n $i | tail -1` machine1=`head $1 -n $nb_lignes | tail -1` ssh root@$machine -x " scp /home/file.txt root@$machine1:/home && rm -r /home/file.txt" done fi ... (2 Replies)
Discussion started by: chercheur857
2 Replies

7. Shell Programming and Scripting

How the user will provide the parameters for Oracle db connection in a shell script?

I'm new into unix. My question: is possible to write a shell script which will ask for the ORACLE_HOME, ORACLE_SID, USERNAME, PASSWORD to connect to Oracle db. In generally we have to set the ORACLE_HOME in .profile file. And after putting the 'sqlplus' command it asks for the username &... (6 Replies)
Discussion started by: priya001
6 Replies

8. Shell Programming and Scripting

oracle connection from shell script

Hi, For connecting to oracle my script is using the command sqlplus username/password@db_instance_name.For this to work i am setting ORACLE_HOME,TNS_ADMIN and ORACLE_SID in a seperate script.My question is,could we make a connection to oracle just by the command sqlplus... (4 Replies)
Discussion started by: DILEEP410
4 Replies

9. Shell Programming and Scripting

Verifying if the shell command executed or not?

Hi, I am working on a shell script that would verify if the mount command has executed or not. So , i have been doing this. mount /dev/cdrom /mnt/cdrom echo "$?" if ; then echo " Mount succesful" else echo " Mount unsuccessful" fi (3 Replies)
Discussion started by: eamani_sun
3 Replies

10. Shell Programming and Scripting

shell script- oracle connection problem

Hi all, I am having problem with a shell script. I have a couple of csv files. The shell script will do some operation on them, create a sql file which will then be called by sqlplus. The problem is to gracefully exit sqlplus at the end of every operation as I do not want to hang on to the... (4 Replies)
Discussion started by: nattynatty
4 Replies
Login or Register to Ask a Question