Read Oracle connection details from a configuration file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read Oracle connection details from a configuration file
# 1  
Old 05-31-2015
Read Oracle connection details from a configuration file

Hi,
Is it possible to pass oracle connection information from a configuration file and use that to connect to oracle database in my unix shell scripts. Following is the scenario:

(1) I would like to save oracle connection string details in a configuration file (ex., dbconfig.txt)
(2) from my unix script, I would like to read this file and store the contents to a variable.
(3) pass this variable to connect to oracle database.

Right now I am able to do (1) & (2), but when it comes to #3, for some reason oracle doesn't seem to accept this.

Request your help to solve this issue.
# 2  
Old 05-31-2015
There are environmental variable settings that have to be in place to do something like that. Plus you can do that fairly easily only on a single application server between processes, not from server1 to server2.

Please show us the output of the set command from both the "passer" and the "passee"
processes. You code would also help a lot. Just snippets are needed.
# 3  
Old 05-31-2015
Hi,
Following is the code that I am using, but as you mentioned my oracle db is in server1 and unix box is in server2. Other thing is if I hard code Oracle DB connection string to a variable as

DB_INFO = "user@pwd@server1", it works but not when read from external file

Code:
echo "Set up Oracle environment"
   PATH=/usr/local/bin:$PATH    ; export PATH
   ORAENV_ASK=NO                ; export ORAENV_ASK
   ORACLE_SID=server1        ; export ORACLE_SID
   . /usr/local/bin/oraenv
   echo "               Oracle_Home is $ORACLE_HOME"
   PATH=$ORACLE_HOME/bin:$PATH  ; export PATH
   LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib ; export LD_LIBRARY_PATH

#Get value from configuration file
DB_INFO=$(<../dev2_config.txt)
export $DB_INFO

Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, output, and code segments.

Last edited by Don Cragun; 05-31-2015 at 11:56 PM.. Reason: Add CODE and ICODE tags.
# 4  
Old 06-01-2015
You have an extra $ on the last line, a typo I think.

Code:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib ; export LD_LIBRARY_PATH

This is good.
Does LD_LIBRARY_PATH and PATH exist for the process using your connect string and are they exactly the same what you have for the process that "works"?

Also please define "doesn't work" - post the oracle error -- you know "ORA-nnnn error message" - are you using a shell script to start oracle (sqlplus for example) - are you using a here document to do that?
Example
Code:
while read connect_string
do
sqlplus -s  $connect_string <<-EOF
 select * from foo;
 exit
EOF
done < external_file


Last edited by jim mcnamara; 06-01-2015 at 12:05 AM..
# 5  
Old 06-01-2015
Yes, LD_LIBRARY_PATH and PATH does exist and are same for both the process that I am doing, one that works and the other where I am trying to get information from configuration file.

I am not getting any oracle error, it just prompts me to enter username and password for oracle and once entered manually, connects and executes the rest of the script.
# 6  
Old 06-01-2015
What output do you get from the command?:
Code:
od -bc < ../dev2_config.txt

# 7  
Old 06-01-2015
After I executed the above command, I saw that there was \n at the end, corrected that and when I run my shell script, I get the prompt to enter username and password and once entered I am getting the error "ORA-12545: Connect failed because target host or object does not exist". Is it because I have @SID?

---------- Post updated Jun 2nd, 2015 at 03:46 AM ---------- Previous update was Jun 1st, 2015 at 08:17 PM ----------

Thanks for all your help...problem resolved...this is what I did...

Code:
#Get oracle database credentials from configuration file
DB_INFO=`cat $parent/dev2_config.txt`
echo $DB_INFO

and that's it...now I am able to connect to database and insert from sample csv file...

thanks again for your help...

Thanks & Regards,
Sudhakara.T.P.

Last edited by Don Cragun; 06-01-2015 at 07:32 PM.. Reason: Add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Unable to fetch BIOS configuration details

Hi All, unable to fetch the bios configuration information and service provider information in centos 5 using dmidecode command. ServiceProvider=`dmidecode -s system-product-name |awk '{print $1}'` BIOS_Configuration=`dmidecode | grep "BIOS Information" -A10 | grep -e... (4 Replies)
Discussion started by: sravani25
4 Replies

2. Shell Programming and Scripting

File read from UNIX to Oracle

hi all, I have flat file in unix. By using sql loader i need to import the data from the flat file. I have created a control file, table with the below data structure and pasted the sample input file. I am not sure whether it is a right way to do it. can anyone provide the thought on this. ... (2 Replies)
Discussion started by: arun888
2 Replies

3. Shell Programming and Scripting

Connection to Oracle data and dump text file

Hi for all! I need for my job one shell script very concrete about connection to oracle databases and writing to text file. Well I tell you: 1.- I must read a file as parameter from linux interface: > example.sh fileToRead 2.-I must read line to line in "fileToRead" and take a... (9 Replies)
Discussion started by: wien996
9 Replies

4. UNIX for Advanced & Expert Users

UNIX / LINUX OS CPU configuration details

Hi, How to find the cpu configuration details of Cores, Speed MHz, virtual processors for the following servers: LINUX OS Servers: Linux 2.6.9-89.0.3.ELsmp #1 SMP Sat Jun 13 07:05:54 EDT 2009 i686 i686 i386 GNU/Linux. (Cores, Speed, Processor) Linux 2.6.18-164.el5 #1 SMP Tue Aug 18... (5 Replies)
Discussion started by: jagtheesh
5 Replies

5. Solaris

Solaris configuration details.

How to find the entire configuration details of a solaris. I need to know what partion were made, which OS is used and wat version is used etc... Thanks to tell (4 Replies)
Discussion started by: kkalyan
4 Replies

6. Shell Programming and Scripting

How to stop Sqlplus command from printing db connection details

Hi, Could someone tell me how to stop SQLPLUS command from printing the connection details in the console. Below is the lines i get in console when executing the sqlplus... SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 9 03:31:03 2011 Copyright (c) 1982, 2005, Oracle. All rights... (2 Replies)
Discussion started by: funonnet
2 Replies

7. Solaris

Configuration details

hi can you please tell me how to get the configuration details from unix server. Rajesh. (6 Replies)
Discussion started by: pmrajesh21
6 Replies

8. Shell Programming and Scripting

How to read the configuration file from shell script

Hello all, Please let me know if anyone have the idea how to read the configuration file from the shell script? Thanks in advance, Nishanth (7 Replies)
Discussion started by: nishanth hampal
7 Replies

9. Shell Programming and Scripting

Read relevent details from Log File

Hi All, We have requirement to read XML details from large Log File and save in new file name. I have enclosed the sample xml which has start tag <OUTBOUND_MESSAGE xmlns="http://www.abc.com"> and the end tag as </OUTBOUND_MESSAGE> The log file contains many lines with other details which... (6 Replies)
Discussion started by: thinakarmani
6 Replies

10. Shell Programming and Scripting

script to read configuration file

Hi, I would like to write a Korn shell script which will remove files older than a certain date. In my script, it will read a configuration file with the following entries: # <directory> <filename wildcard> # /home/philip/log *.log /home/philip/log1 delete-me*.log The... (1 Reply)
Discussion started by: philip_dba
1 Replies
Login or Register to Ask a Question