Visit Our UNIX and Linux User Community


calling two procedures from one ksh ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calling two procedures from one ksh ???
# 1  
Old 10-29-2009
calling two procedures from one ksh ???

Hi to all,
This is first posting in this forum. I quite new to this KSH....i guess i ll have some fun...Smilie

Well, I have two indivdual korn shell scripts. i m calling PL/SQL stored procedure from korn shell script. It works absolutely fine. Once its completed the log is updated and data is loaded into tables. These two loades the data into two different tables. Then have dependency.

So i have to run A.ksh and Later B.ksh. If i run B.ksh first then data will not be loaded since it has dependency on A.ksh.

So i was trying to merge into one korn shell script. First run 1st procedurer if successfully completed then run 2nd procedure. if 1st procedure is failed then dont run 2nd procedure.

So how do i accomplish this in korn shell script ??? Any idea guys


Thank you so much in advance !!!
# 2  
Old 10-29-2009
I'm assuming that you are using sqlplus... You have not specified any details.

Check the sqlplus manual... Since it is very limited, you would need to parse its output.
I would guess that PL/SQL might be the right choice... but you need to check it.

In a brief: According to POSIX application should return ($?) a value of 0 if it was finished with a success. SQLPLUS can perform multiple operations and you won't get the result from a single operation. You might want to try perl or python or java.

General idea: Korn shell should be used for simple things (although it can perform complex things either). If you do anything that is complex then you need to use some real programming language (perl, python, java, c++,...).
# 3  
Old 10-29-2009
Why can't you just add the command to kick off the second script (b.ksh) inside the first script (a.ksh) at the end?
# 4  
Old 10-29-2009
I agree with this:

Quote:
Originally Posted by adderek
I'm assuming that you are using sqlplus... You have not specified any details.
Don't understand this:
Quote:
Originally Posted by adderek
Check the sqlplus manual... Since it is very limited, you would need to parse its output.
I would guess that PL/SQL might be the right choice... but you need to check it.
And completely disagree with this:
Quote:
Originally Posted by adderek
General idea: Korn shell should be used for simple things (although it can perform complex things either). If you do anything that is complex then you need to use some real programming language (perl, python, java, c++,...).
# 5  
Old 10-29-2009
At work we have many scripts (ksh) that integrate with DB2 and perform many complex DB operations, way beyond simply running SQL scripts.

If you do want to perform complex DB operations from shell it is good to break the code down into specific operations, such as: -
  • Connect to the database
  • set schema
  • update table
  • delete
  • insert
  • disconnect
and so on. Each of these actions are performed by specific functions written in a common library file that is dotted into scripts running under sudo. Expected return codes are passed to each function so they can fail if a code is out of range.

One script for example connects to a database with over 200 tables and verifies: -
  • No tables have changed their name
  • No field names have changed
  • No data types have changed
  • No field sizes have changed.
As a manual exercise this was a day's work for the testers and very error prone. Now it is performed in a few minutes with any changes presented in a report.

So don't let any one tell you you cannot perform complex operations in shell. At the last line count the tool suite had almost 2,000,000 lines, albeit a lot of that standing data.

Last edited by steadyonabix; 10-30-2009 at 10:28 AM..
# 6  
Old 11-02-2009
Quote:
Originally Posted by scottn
I agree with this:
Don't understand this:
What is here to understand? He needs an interaction with the database - and it might be better way to do it within a single transaction (or several related transactions if DDL is performed). Since it might be difficult in sqlplus - you need another option. Perl's DBI might be a choice. I believe that a PL/SQL code (might be anonymous) might be a better choice.

Quote:
Originally Posted by scottn
And completely disagree with this
I have written that you should not (note the difference between "should not" and "cannot") use korn shell for complex code. Not that it cannot be used for complex things - it can do artificial inteligence if you want it to. However for complex things other choices (perl, python, java, ...) are usually much more optimal.
If you don't agree then I wish you luck in writing 3D accelerated games in ksh Smilie

Complex ksh code might be difficult to read and maintain. Code might be distributed across thousands of scripts executed as functions named like a_my_function which is in fact "${x}_${y}_${z}". There is no separation between modules and people tend to use variables without declaration (try running "set -u"). You don't have references, objects, streams, inheritance, overloading, debugging, libraries, private methods, multi-threading, ...
You can find several games written in shell... try reading that mess. Then compare it to other game sources.

As for the original question, you wanted to:
1. Run some script, let say A.sql
2. Check if A.sql failed
3. Run B.sql if A.sql did not fail... probably rollback the changes if A.sql failed
In shell you would need to spool the output from sqlplus, grep it and quess what might fail (ex. grep the output by "error" string and be lucky to have there nothig like "create table my_errors(error char(10))") with checking the return code and then execute the second script.
PL/SQL script might try to work in a single transaction and have "rollback" in the exception handler. If you use any DDL there then flashback mechanism might be used.

Previous Thread | Next Thread
Test Your Knowledge in Computers #637
Difficulty: Easy
As of January 2017, Apple's App Store had over 2.2 million apps for the iPhone.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Calling subscript with sh vs. ksh

I ran into an issue today that I was able to resolve, but I don't quite understand why the resolution worked. I'm wondering if anyone can help me make sense of it. I have a "kicker" script that calls 4 subscripts on a RHEL 6.9 server. It calls the scripts in sequence checking for a 0 exit code... (5 Replies)
Discussion started by: derndingle
5 Replies

2. Shell Programming and Scripting

Calling Oracle stored procedure from ksh script

Friends, I'm newbie with ksh so wanting some help.... 1. I'm trying to call oracle stored procedure from ksh script by taking variable value from runtime, feed into script and execute procedure. 2. Put name1 and name2 value from script run replacing $3 & $4 I'm trying to put name1 in... (4 Replies)
Discussion started by: homer4all
4 Replies

3. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

4. Shell Programming and Scripting

Calling Function in KSH

I have a script with 2 functions 1) show_menu 2) create Ths show_menu function works fine....... Sort of.... When I select option 2 of the menu the code does a few commands and then calls another function called create. It's at this point that I get "create: not found"..... However,... (2 Replies)
Discussion started by: hxman
2 Replies

5. Shell Programming and Scripting

calling jar file from ksh

Hi, I have a below command in ksh .... $JAVA_HOME/bin/java -cp "/usr/orabase/product/10.2.0/lib:/usr/java/javajar/common/sched.jar:/usr/orabase/product/10.2.0/jdbc/lib/ojdbc14_g.jar:/usr/orabase/product/10.2.0/jdbc/lib/classes12.jar" com.abrt.smart.Smart I want to know where the... (1 Reply)
Discussion started by: PRKS
1 Replies

6. Shell Programming and Scripting

Get return value from PERL script calling from KSH

All: I am calling a PERL script from KSH. I need specific codes to be returned by the PERL Script. For ex: Ksh ----- result=`test.pl $FILE` My idea is to get the value of result from the test.pl, by specifically making the test.pl to print the return code. Since I had some other print... (1 Reply)
Discussion started by: ucbus
1 Replies

7. Shell Programming and Scripting

calling csh script from ksh shell

hi, I have a csh script, which has setenv X xyz etc My shell is korn Is there some way I can "source" this to have the variables in my current korn shell? thanks (3 Replies)
Discussion started by: JamesByars
3 Replies

8. Shell Programming and Scripting

calling a ksh script present in different unix box

Hi , I have a shell script which does some calling of procedures once all the procedures are called I need to start another ksh script which is present on a different unix box How can this be done ? Do I need to open a telnet session to connect to that box in my first script and... (1 Reply)
Discussion started by: Navatha
1 Replies

9. Shell Programming and Scripting

calling a PL/SQL stored procedure from KSH

Hi I have a stored procedure which should be called from KSH. Could ayone please help me with this. Thanks (1 Reply)
Discussion started by: BlAhEr
1 Replies

10. Solaris

Calling Oracle Stored Procedures in UNIx(sun solaris)

I have created 3 Procedures all similar to this one: I then created 3 shell sripts which will call the sql? finally created a calling script to call the procedure. I am a bit unsure how to this all works, can someone check my code and I am doing this right? Also could I add my procedure (first... (0 Replies)
Discussion started by: etravels
0 Replies

Featured Tech Videos