Solved

Connecting to another server from ksh script

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

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

785 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