Solved

Connecting to another server from ksh script

Posted on 2013-06-21
4
628 Views
Last Modified: 2013-06-27
On one UNIX server I have a ksh script and from my script I need to connect to another UNIX server to an Oracle database and insert some data.

So far I got:

sqlplus 'username/pwd@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHostname)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myDB)))' >> output.log

to connect to the server but how do I run an insert statement?
0
Comment
Question by:YZlat
  • 2
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39267216
Assuming you have a list of values you can embed in the script, try the code below.  It is called a HERE document.

sqlplus 'username/pwd@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHostname)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myDB)))' << EOF >> output.log
insert into some_table values('hello','world');
commit;
exit
EOF


If you have something else, please explain.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39281196
slightwv, are there any advantages to put the entry into tnsnames.ora and just use an alias, over listing the whole tns entry in the script?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39281210
There are pro's and con's.

If everything is in the tnsnames.ora file and all apps/scripts use it then you can easily change database servers and/or database names and no app/script needs to change.

The counter-point:
You need to rely on another configuration file for your apps/scripts to work.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39281506
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now