Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Connecting to another server from ksh script

Posted on 2013-06-21
4
Medium Priority
?
686 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 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 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 78

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

927 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