Solved

Connecting to another server from ksh script

Posted on 2013-06-21
4
640 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 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.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

791 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