check the DB connection through Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check the DB connection through Unix
# 1  
Old 05-04-2012
check the DB connection through Unix

Hi all,

I have written the script to check the connectivity of the Database ,the scripts show me the correct error when i try to give the wrong credential's but it also show Connected and trigger's the child jobs which that should not happen , whenever the connection is not established properly it should exit from the script, which is not happening in my script..please look into the script below and let me know the changes please
-------------------------------------------
Script
---------------------------------------------
Code:
#!/usr/bin/bash
. /etc/profile.local
. /usr/local/lib/job_functions
. /infa_shared/infadev_d2/ShellScripts/xxx/bin/set_env
export foldername='m'
export wfname='s'
flag='N' #value used to test if DB connection is sucessfull, default is no
uid=bbb #userid for the Database
pwd=111 #password for Database
hostname=yyy #Hostname of the Database
while [ ! -f /user/shiv/flag.trg ] #while loop,loop untill flag is set to Y
do
  sqlplus -s /nolog <<ENDSQL
  connect bbb/111@yyy
  WHENEVER SQLERROR EXIT SQL.SQLCODE
  WHENEVER OSERROR EXIT 10
  EXIT;
  ENDSQL
  if [ $? -eq 0 ]
  then
    echo 'connected OK'
    . /infa_shared/infadev_d2/ShellScripts/xxx/bin/execute_workflow $foldername $wfname
    touch /user/shiv/flag.trg #Set the flag to Y to exit the loop as the workflow is complete
    chmod 777 /user/shiv/flag.trg
  else
    echo 'connection FAIL'
    sleep 10 #Sleep for 10 secs and again loop through
  fi
done
rm /user/shiv/flag.trg

-----------------------------------------------------------------
output of the script
------------------------------------------------------------
Code:
-bash-3.00$ DB_Connection
ERROR:
ORA-01017: invalid username/password; logon denied

connected OK
-bash-3.00$

Thanks in Advance

Last edited by Franklin52; 05-04-2012 at 05:47 AM.. Reason: Please use code tags
# 2  
Old 05-04-2012
One correction:
Code:
while [ ! -f /user/shiv/flag.trg ] #while loop,loop untill flag is set to Y
do
  sqlplus -s /nolog <<ENDSQL
  connect bbb/111@yyy
  WHENEVER SQLERROR EXIT SQL.SQLCODE
  WHENEVER OSERROR EXIT 10
  EXIT;
ENDSQL

ENDSQL has to be in the leftmost column.


Why can you not use tnsping?
# 3  
Old 05-04-2012
The WHENEVER directives get activated after you connect. Set them before you try to connect:
Code:
...
while [ ! -f /user/shiv/flag.trg ] #while loop,loop untill flag is set to Y
do
  sqlplus -s /nolog <<ENDSQL
  WHENEVER SQLERROR EXIT SQL.SQLCODE
  WHENEVER OSERROR EXIT 10
  connect bbb/111@yyy
  EXIT;
ENDSQL
...

@jim: tnsping only tells you if there is a listener accepting connections but not if there's a database to connect to...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check internet connection?

Hello, I need a simple shell script that returns a value if the system is internet connected and a different value if the system is not connected. Can anyone please help? Thanks Daniele (3 Replies)
Discussion started by: dcaccount
3 Replies

2. Shell Programming and Scripting

Need Script to check the FTP connection

Hi, I need a script which check the FTP connections, if its working fine then no issue. Incase not working fine then Trigger the mail. Please help on this. Thanks (4 Replies)
Discussion started by: Keshav Kalra
4 Replies

3. Shell Programming and Scripting

simple while loop script to check a connection

Hi, I am completely new to shell scripting. Basically I am wanting to create a simple while loop script to check if a network connection is available from 'netstat -a' and if its present then output a character to the serial port. I think i am nearly there.. but need some assistance.. this is... (9 Replies)
Discussion started by: zippyzip
9 Replies

4. Shell Programming and Scripting

How to check sftp connection

Hi All, in our system , the sftp server is continuously up. but suddenly it is brought down. how can i find out the reason behind of these , is their any log files or how can i check the connectvity with sftp. please help me to solve this issue (1 Reply)
Discussion started by: aish11
1 Replies

5. Programming

TCP connection check

Hi. I am writing client - server application using TCP sockets. I need some very basic functionality, namely: how to check if another "participant" of the connection is still present? I want to handle situations, when client is gone, or server breaks down, etc. (25 Replies)
Discussion started by: Shang
25 Replies

6. UNIX for Dummies Questions & Answers

How can I check UDP connection to other server?

Hi, My network dep. telles me that they have opened the FW but my application still can not get through to other server. If it was TCP I could simply test it myself with "telnet", but how can I check it when the connection is UDP? Tnx (1 Reply)
Discussion started by: mehrdad68
1 Replies

7. UNIX for Dummies Questions & Answers

check Internet connection?

I am using SUSE OS and want to check internet connection... I have tried: ping -c3 google.com The output i have got is: Unknown host google.com does it means that i do not have Internet connection?? Or please help me with any Command to find Internet connection? Thanks for any help. (1 Reply)
Discussion started by: salil2012
1 Replies

8. Solaris

Check SSH Connection .. help ..

I've script where i check connection to many hosts ... it take input from HOSTLIST.txt Ex. cat HOSTLIST.txt host1 host2 while read HOSTNAME do echo $HOSTNAME ssh -o "BatchMode=yes" ${HOSTNAME} "echo 2>&1" $$ echo flag=0 || flag=1; if ; then echo "No SSH... (3 Replies)
Discussion started by: prash184u
3 Replies

9. Shell Programming and Scripting

how to check DB connection in unix shell script

In the following script I need to find whether DB is established successfully or not. I need to find and display it. If <DB is connected successfully> then echo "DB connection success" else echo "DB connection failure" fi In the same way I need to do it for DB terminate. I don't... (1 Reply)
Discussion started by: kmanivan82
1 Replies

10. UNIX for Dummies Questions & Answers

SQL Connection check though Scripting

Hi Guys, I wanted to check the sql connection through scripting if it is avilable then proceed else stop the process I was trying sqlplus -L username/passwd@sid if this is not sucess it gives non-zero. but if it is success it is going into the sqlplus prompt. So how could i get out... (2 Replies)
Discussion started by: Swapna173
2 Replies
Login or Register to Ask a Question