Database Connection test in unix Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Database Connection test in unix Script
# 1  
Old 06-30-2009
Database Connection test in unix Script

i have a unix script that gives me the sysdate from the database EDNAMID.WORLD.What i want my script to do the following

1) Establish a database connection
2) if database connection is successfull then echo the message "Connected"
3) put the o/p of the Sql query in a spool file
4) then disconnect from the database by echoing the message "disconnected"

Below is the script that i have written :

Code:
#!/bin/ksh
sqlplus -silent Aix/full@ednamid.world @"naveed.sql"<<END
END

code in the sql file naveed.sql
Code:
set pagesize 1000 line 1000 feedback off verify off heading off echo off
spool /ednadtu3/u01/pipe/naveed/test/database/d1.txt
select sysdate from dual;
spool off;
exit;

what i want is how to implement the steps 2 and 4 and in which code
# 2  
Old 06-30-2009
What I did previously was to verify the connection status only after the connection. For your reference as follow (ksh):

Code:
LOGIN_STATUS=`sqlplus -s /nolog <<SQLEND
connect ${UserName}/${PassWord}
set pagesize 1000 line 1000 feedback off verify off heading off echo off
spool /ednadtu3/u01/pipe/naveed/test/database/d1.txt
select sysdate from dual;
spool off;
exit;
SQLEND`

echo ${LOGIN_STATUS} |grep "ORA-" >> /dev/null

LOGIN_STATUS=$?

if (( $LOGIN_STATUS ))
then
     echo "Connected"
else
     echo "Problem connecting"
fi

# 3  
Old 06-30-2009
Where should i write this code inside my unix script or sql file ? Also where do i put the database name ednamid.world
# 4  
Old 06-30-2009
Quote:
Originally Posted by ali560045
Where should i write this code inside my unix script or sql file ? Also where do i put the database name ednamid.world
That would be an entire shell script handling all the way, including what the sql file is doing.

However you need to ensure your oracle environment settings are all set
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Oracle Database connection from UNIX

Hi I have a question regarding Oracle connection using the below code ${ORACLE_HOME}/bin/sqlplus -s $user/$pwd@$sid <<!EOF 1>> $v_log_dir/$v_job_log.out 2>> $v_log_dir/$v_job_log.err / prompt stored procedure beginning . . . exec xx_interface_pkg.pr_xx_clms_out($datayears,$keepmonths); ... (3 Replies)
Discussion started by: smilingraja
3 Replies

3. UNIX for Dummies Questions & Answers

Shell Script to test telnet connection using port

Hello, I need to test telnet connections using port number for few hosts. Could you please help me? Thanks !! (1 Reply)
Discussion started by: skhichi
1 Replies

4. Ubuntu

Database Connection

Hi, How to creating connection to mysql.I try to connect but the following error coming .How to solve it. Could not connect to New MySQL. Error creating SQL Model Connection connection to New MySQL. (Error: com.mysql.jdbc.Driver) com.mysql.jdbc.Driver Error creating JDBC Connection... (2 Replies)
Discussion started by: snallusami
2 Replies

5. Shell Programming and Scripting

bash script to test network connection - please help

I want to test if my host can connect to any of the following 10 hosts (192.168.1.0 to 192.168.1.9) I didnt know which command i should use, so i chose ping. (i wonder if i should use tracepath or sth else) my code is the following: #!/bin/bash clear firstPart="192.168.1" maxNum="9" ... (2 Replies)
Discussion started by: shadow_boi
2 Replies

6. Shell Programming and Scripting

Connection Test Script

I am writing a script to do some conditional logic based on the results of a connection test. I need to capture the output of netcat, the 3 expected conditions are as follows. I need to capture the output of this command. I could write this to a file, but I would like to do it clearer if possible.... (1 Reply)
Discussion started by: princeboot
1 Replies

7. Shell Programming and Scripting

Wrapper script to refresh test database with production data

Hi All, I'm new here as well as to UNIX. I need to write a wrapper script to refresh test database with production data. A set of tables are given as well as a particular data range. The script should prompt the user for both production and test logon credentials. Pl. help me with this.... (2 Replies)
Discussion started by: linslet
2 Replies

8. Shell Programming and Scripting

How to Create a shell script to test the telnet connection status

Hi friends, I'm newbie to shell script. I wanted to create a shell script which able to write a result for all the telnet connection status. For example, from this machine I want to test the telnet connection (total 100+ servers) with this machine. Any idea how to write this shell script?... (16 Replies)
Discussion started by: yhcheong
16 Replies

9. Shell Programming and Scripting

Connection to database through shell script

Hi when i am calling the shell script with two parameter like id and date it works fine.But the same shell script is call by java application it gives the error as shown below Thu Jan 8 04:13:22 EST 2009|The Get Segment Process Failed: SP2-0306: Invalid option. Usage: CONN where <logon>... (1 Reply)
Discussion started by: ravi214u
1 Replies

10. UNIX for Dummies Questions & Answers

Connection problem with gui java program to postgreaql database using unix

Having problem in connecting my gui java program to postgreaql database. I first used setenv classpath /home/share/postgresql/java/postgresql.jar:proj1, where proj1 is my folder conatining all java and class file, to set classpath. Then javac *.java. Then java proj1.Login. It gives me... (2 Replies)
Discussion started by: uci
2 Replies
Login or Register to Ask a Question