Welcome Guest ( Log In | Register )


 
 
 
 
 
 

 
 
Oracle 

Performance Tuning Reference poster
 
Oracle training in Linux 

commands
 
Oracle training Weblogic Book
 
Easy Oracle Jumpstart
 
Oracle training & performance tuning books
 
Burleson Consulting Remote DB Administration
 
 
 
Reply to this topicStart new topic
> remote connection to oracle db using bash script
c0d3
post Dec 17 2004, 09:07 PM
Post #1


Newbie
*

Group: Members
Posts: 3
Joined: 5-December 04
Member No.: 1,093



Dear Guys,
I would like to ask for a sample bash script on how can I connect to a remote oracle database. Thanks in advance.
Go to the top of the page
 
+Quote Post
dave
post Dec 18 2004, 12:11 PM
Post #2


Advanced Member
***

Group: Members
Posts: 5,206
Joined: 8-October 04
Member No.: 785



how about write it yourself then we can check it over for you
Go to the top of the page
 
+Quote Post
Tom
post Dec 19 2004, 04:49 AM
Post #3


Advanced Member
***

Group: Members
Posts: 78
Joined: 30-September 04
Member No.: 731



Hi folks,

... bash connecting to an oracle database?
IŽd say: SQL*Plus is connecting to an oracle database, never seen a shell doing this directly wink.gif

So you will have to install an Oracle-client onto your system, configure tnsnames.ora and then have fun.

> sqlplus username@remote_database

tom
Go to the top of the page
 
+Quote Post
edwardstoever
post Dec 19 2004, 01:54 PM
Post #4


Advanced Member
***

Group: Members
Posts: 555
Joined: 29-October 04
From: California
Member No.: 923



It is true that a bash script cannot connect to the database, but it can run SQLPLUS. I am no Unix master, but I will give it a go on linux and see what we get.

t.sh:
CODE
sqlplus system@test/password @dd.sql

then you have to change the t.sh file so it can be executed:
QUOTE
$ chmod 777 t.sh

Then create the dd.sql file:
CODE
spool results.txt
select 'SUCCESS' from dual;
spool off
exit

Now run it:
QUOTE
$ ./t.sh

now check the spooled results:
QUOTE
$ more results.txt

'SUCCES
-------
SUCCESS


Hey it works!

Edward
wink.gif
Go to the top of the page
 
+Quote Post
JGarmany
post Dec 21 2004, 01:41 PM
Post #5


Advanced Member
***

Group: Members
Posts: 359
Joined: 18-March 04
Member No.: 57



I use bash as my shell but script using Korn. By placing

#!/bin/ksh

at the beginning of the script I tell Linux/Uninx to execute the script using the ksh shell. Here is part of a ksh script that I use to start my test database.

#!/usr/bin/ksh
#
# source the environment
. /home/oracle/db.env
# start the database
$ORACLE_HOME/bin/lsnrctl start
#
$ORACLE_HOME/bin/sqlplus -s /nolog << EOF
connect / as sysdba
startup
select * from v$version;
exit
EOF


Basically this starts sqlplus in silent mode without loging on so that the username and password are not viewable using the ps command.
Then the script sends each command to sqlplus unitl it encounters the EOF marker.

Hope that helps
John


--------------------
Regards,

John Garmany
Oracle Certified DBA
garmany@dba-oracle.com
Go to the top of the page
 
+Quote Post
c0d3
post Dec 22 2004, 02:06 AM
Post #6


Newbie
*

Group: Members
Posts: 3
Joined: 5-December 04
Member No.: 1,093



guys,i already figured out the lacking portion of my script. I just added to initialize my oracle environment cause my crontab runs on oracle user. thanks for all your feedback.
Go to the top of the page
 
+Quote Post
metacharacter
post Dec 22 2004, 02:26 PM
Post #7


Advanced Member
***

Group: Members
Posts: 79
Joined: 26-November 04
From: Mumbai
Member No.: 1,074



QUOTE (JGarmany @ Dec 21 2004, 06:42 PM)
I use bash as my shell but script using Korn. By placing

#!/bin/ksh

at the beginning of the script I tell Linux/Uninx to execute the script using the ksh shell. Here is part of a ksh script that I use to start my test database.

#!/usr/bin/ksh
#
# source the environment
. /home/oracle/db.env
# start the database
$ORACLE_HOME/bin/lsnrctl start
#
$ORACLE_HOME/bin/sqlplus -s /nolog << EOF
connect / as sysdba
startup
select * from v$version;
exit
EOF


Basically this starts sqlplus in silent mode without loging on so that the username and password are not viewable using the ps command.
Then the script sends each command to sqlplus unitl it encounters the EOF marker.

Hope that helps
John

Why ?
What adv do you get by using korn instead of bash?


--------------------
If you're never scared or embarrassed or hurt, it means you never take any chances.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 24th October 2014 - 08:27 AM