connect to sqlplus from shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting connect to sqlplus from shell
# 1  
Old 02-07-2007
connect to sqlplus from shell

I'm writting a shell script and at the begining I login to sqlplus by
sqlplus -l user_name/password@instance
what I would like is to check if the database is down or not , and if the database has started moved to the next step else sleep for a certain time and then check again .
I know how to do the sleep part, but I don't know how to check if the database is not down. can some one help me please.

Thanks,
# 2  
Old 02-07-2007
you can check with $? status.if database is down you will not be able to connect with data base.

if [ $? != 0 ]
then
PROGRAM_STATUS=`echo NOT CONNECTED TO SQL`
fi

you may check another post here
# 3  
Old 02-07-2007
am using infomix database on unix os


Code:
if [ `tbstat - | grep On-Line | wc -l` -eq 0 ]
then
        echo Informix database seems to be down. Please start the database
        echo do this do this
else
        echo database is running
        echo do this
fi

where tbstat is used to find database status...here you have to find out the command which gives status of your database....
# 4  
Old 02-07-2007
Quote:
Originally Posted by aya_r
I'm writting a shell script and at the begining I login to sqlplus by
sqlplus -l user_name/password@instance
what I would like is to check if the database is down or not , and if the database has started moved to the next step else sleep for a certain time and then check again .
I know how to do the sleep part, but I don't know how to check if the database is not down.
[...]

For quick and "dirty" check you can use something like this:

Code:
oracheck ()
{
  printf "whenever sqlerror exit failure\nselect null from dual;\n" |
  sqlplus -sl user/pass 2>&- 1>&- || return 1
}


Usage:

until oracheck; do sleep n; done
go_to_the_next_step

# 5  
Old 02-07-2007
If its on Informix use
Code:
 onstat -

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sqlplus shell

friends because when calling a sqlplus from a shell it brings me the following message sqlplus -s $BDDUSER/$BDDPASS@$BDDHOST @$DIR_SQL/prueba.sql echo "bandera 3 " $? STATUS=$? if ;then echo "bandera 4 " $? #log_info "La ejecucion de... (1 Reply)
Discussion started by: tricampeon81
1 Replies

2. Shell Programming and Scripting

Connect to Oracle using sqlplus

I have logged into oracle using SQLPLUS. When I type any kind of query, there is only 1 answer - '2'. What is wrong with it? (1 Reply)
Discussion started by: Subhasis
1 Replies

3. UNIX for Advanced & Expert Users

Unable to connect to sqlplus from unix

Hi, I have been trying to connect to sqlplus the same way I used to do in my earlier company but I get these error messages , please suggest way out - user name - xyzuser schema name - xyzschema $ sqlplus xyzuser@xyzschema ksh: sqlplus: not found. $ sqlplus -s xyzuser@xyzschema... (5 Replies)
Discussion started by: dhirajdsharma
5 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. Programming

Shell SQLPlus

Hi, I am trying to execute the update statment in shell sqlplus.But nothing prompts.if i do ctrl+c i got the below error. SQL> update table set enabled='N' where type_code='xx'; ^C update table set enabled='N' where type_code='xx' * ERROR at line 1: ORA-01013: user requested... (2 Replies)
Discussion started by: nmahendran
2 Replies

6. UNIX for Dummies Questions & Answers

Switch from SQLPlus to shell?

What is the command for when you are in SQLPlus and want to go back to the shell prompt without actually exiting SQLPLus? Thanks. (2 Replies)
Discussion started by: Sepia
2 Replies

7. UNIX for Dummies Questions & Answers

connect sqlplus from unix

hi, I have this basic query. I have created a new user on unix. I have given home directory and permission through chmod to create directory stucture. Now need to connect sqlplus. What permissions should we give, so that this works? Any help is appreciated. Thanks, Neha (1 Reply)
Discussion started by: nehak
1 Replies

8. 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

9. Shell Programming and Scripting

calling sqlplus from shell

Hi All, I am executing the following code :- sqlplus -s ${DATABASE_USER} |& print -p -- 'set feed off pause off pages 0 head off veri off line 500' print -p -- 'set term off time off serveroutput on size 1000000' print -p -- "set sqlprompt ''" print -p -- "SELECT run_command from... (2 Replies)
Discussion started by: suds19
2 Replies

10. UNIX for Dummies Questions & Answers

sqlplus and shell scripting

i would like to learn how to integrate my little knowledge in shell scripting with sqlplus. well... i know how to make basic query in sqlplus but i dont know how i can integrate it with shell script. can someone :) please help me on this? can you give me some basic example on how to do this kind of... (10 Replies)
Discussion started by: inquirer
10 Replies
Login or Register to Ask a Question