Oracle (11gr2) calling unix commands (aix)


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Oracle (11gr2) calling unix commands (aix)
# 1  
Old 06-20-2010
Oracle (11gr2) calling unix commands (aix)

I have an Oracle database running on AIX, and I have a procedure that is calling OS commands from an oracle (and it's not working anymore)...

so, there was an Java stored proc in Oracle

Code:
CREATEORREPLACEANDRESOLVEJAVASOURCENAMED COMMON."Host"as import java.io.*;
public class Host {
public static void executeCommand(String command){
try {
String[] finalCommand;
if (isWindows()){
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0]="C:\\windows\\system32\\cmd.exe";// Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
finalCommand[1]="/y";
finalCommand[2]="/c";
finalCommand[3]= command;
}
else {
finalCommand = new String[0];
//finalCommand[0] = "/bin/sh";
//finalCommand[1] = "-c";
//finalCommand[2] = command;
finalCommand[0]="/bin/sh -c '"+ command +"'";
}

final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
new Thread(new Runnable(){
public void run(){
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine())!= null){
System.out.println("Process out :"+ buff);
try {Thread.sleep(100);} catch(Exception e){}
}
br_in.close();
}
catch (IOException ioe){
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
}
finally {
try {
br_in.close();
} catch (Exception ex){}
}
}
}).start();

new Thread(new Runnable(){
public void run(){
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine())!= null){
System.out.println("Process err :"+ buff);
try {Thread.sleep(100);} catch(Exception e){}
}
br_err.close();
}
catch (IOException ioe){
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
}
finally {
try {
br_err.close();
} catch (Exception ex){}
}
}
}).start();
}
catch (Exception ex){
System.out.println(ex.getLocalizedMessage());
}
}

public static boolean isWindows(){
if (System.getProperty("os.name").toLowerCase().indexOf("windows")!=-1)
return true;
else
return false;
}
};
/

and a procedure that calls it:

Code:

CREATEORREPLACEPROCEDURE COMMON.host_command(p_command INVARCHAR2)
ASLANGUAGEJAVA 
NAME'Host.executeCommand (java.lang.String)';
/

and it was working by calling (for example):

Code:

begin
common.host_command('/usr/bin/pwd > /tmp/abc123');
end;

now, it's not working... it's dead...

is it because we deleted extproc from a listener.ora?
# 2  
Old 06-21-2010
Quote:
Originally Posted by bongo
...
now, it's not working... it's dead...

is it because we deleted extproc from a listener.ora?
It might be a permission problem - did you grant the appropriate Java permission to the schema owner ?

Also, check for messages in your trace file. Log in to SYS or any user that has DBA privileges and -

Code:
show parameter user_dump_dest

Then change to the directory (specified in the VALUE column) and check if there are any "*.trc" files generated after you run your anonymous PL/SQL block. It should tell you what's wrong.

If there are no "trc" files then we really don't know that it is running.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

calling perl commands in shell

i have four commands 1. perl -MCPAN -e shell 2. o conf prerequisites_policy follow 3. o conf commit 4. exit I am attempting to streamline a bunch of yum commands and cpan installations and want to remove the confirmation portion of the cpan these four commands will do just that. my... (2 Replies)
Discussion started by: murphybr
2 Replies

3. Shell Programming and Scripting

Calling oracle package Unix from shell scripts.

Hi, Can anyone tell me how to call a oracle package from a Unix shell script? I want to pass some input parameters to package and it will return me the output which I want to use further in my shell script. I want to know the way to capture the output values in my shell script. Please send some... (1 Reply)
Discussion started by: anil029
1 Replies

4. Programming

calling UNIX commands C/C++

hi Guys, I am planning to write a program which can be able to execute scripts/commands which needs a user to be root. Note: we are not interested to use sudoers option. .e.g. The requirement can be explaind as: A normal UNIX system user cannot execute above command(veritas cluster... (3 Replies)
Discussion started by: Asteroid
3 Replies

5. Shell Programming and Scripting

Calling GDB commands from Shell

Hi, I have just started off with the shell programming. I need to execute a GDB command from a shell script. I have been trying to get this working from quite sometime but not getting it quite right.I have this specific requirement that i read byte data from a file and write that data to the... (0 Replies)
Discussion started by: jsantosh
0 Replies

6. Shell Programming and Scripting

Calling an Oracle Stored Procedure from Unix shell script

hai, can anybody say how to call or to execute an oracle stored procedure in oracle from unix... thanks in advance.... for ur reply.... by, leo (2 Replies)
Discussion started by: Leojhose
2 Replies

7. Shell Programming and Scripting

Perl calling unix system commands

if ( system ("/bin/cat $File1 >> $File2") ) { print("#WARNING RAISED : /bin/cat File1 >> File2 - FAILURE!\n"); } I came across this code, would appreciate if someone can tell me if my understanding is correct? the perl code tell the system to cat file 1 into file 2, if command fails, print... (4 Replies)
Discussion started by: new2ss
4 Replies

8. UNIX for Dummies Questions & Answers

calling Oracle procedure from Unix

Does anyone know how to call an Oracle stored procedure from a Unix script? (1 Reply)
Discussion started by: ssmiths001
1 Replies

9. 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

10. AIX

AIX and SUN unix commands for hardware monitoring

Hello again, I would like to know if the following commands: diag, errpt, lscfg, lspv, lsvg, lsps, lslv for AIX and prtdiag, psrinfo, sysdef for SUN are native to these systems or if they are in fact scripts that are added after the unix installation. Thank you in advance. Have a nice day (4 Replies)
Discussion started by: VeroL
4 Replies
Login or Register to Ask a Question