Home » RDBMS Server » Server Utilities » java option to run OS Command fails with some process (oracle,10.2,SunOS)
java option to run OS Command fails with some process [message #355935] |
Tue, 28 October 2008 11:20 |
ciri
Messages: 11 Registered: October 2008
|
Junior Member |
|
|
Hello
I´m running Oracle 10.2 in a Sun OS.
I´ve got a java source object which run a OS program. But it is not able to run some programs. For example, it runs ok the unix process "who", but it is not able to run the exp tool. When i try to run exp, I get:
"can´t exec: /aplicaciones/oracle/oradcli02/10.2.0/bin/exp doesn´t exist"
The point is that the executable do exist, and I´ve put the path properly.
I think I have a file system permission problem.
My user info is:
uid=43000(xxxxx) gid=43000(xxxxx)
The who process info is:
-r-xr-xr-x 1 root bin 13088 Apr 3 2001 /usr/bin/who
The exp process info is:
-rwxr-xr-x 1 oracle dba 809224 Feb 6 2008 /aplicaciones/oracle/oradcli02/10.2.0/bin/exp
I don´t know what should i do.
Can anybody help me?
Thanks in advanced.
[EDITED by LF as per OP's request]
[Updated on: Mon, 20 July 2009 02:45] by Moderator Report message to a moderator
|
|
|
|
Re: java option to run OS Command fails with some process [message #356046 is a reply to message #355946] |
Wed, 29 October 2008 03:14 |
ciri
Messages: 11 Registered: October 2008
|
Junior Member |
|
|
Hi,
I have rewritten and formated the question. I hope it matchs requirements
I use oracle 10.2.0.3.0 and SunOS 5.8.
First of all, I put the code i use inside my database.
create or replace and compile java source named "xxxxUtil"
as
import java.io.*;
import java.lang.*;
public class xxxxUtil extends Object
{
public static String RunThisS(String args)
{
Runtime rt = Runtime.getRuntime();
String rcS = "";
int rc = -1;
try
{
Process p = rt.exec(args);
int bufSize = 8192;
BufferedInputStream bis =
new BufferedInputStream(p.getInputStream(), bufSize);
int len;
byte buffer[] = new byte[bufSize];
// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);
rc = p.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
rcS = e.getMessage();
}
finally
{
return rcS + rc ;
}
}
}
/
create or replace package xxxx_BACKUP
is
-- Author : xxx
-- Purpose : Procedimientos para realizar el Backup de
-- los objetos de base de datos
-- Ejecuta un comando del sistema
FUNCTION RUN_CMD(p_cmd in varchar2) return VARCHAR2;
-------- EXPORT ESQUEMA --------
PROCEDURE backup_esquema(ruta_exp IN VARCHAR2,usuario IN VARCHAR2,
contrasenia IN VARCHAR2,nombre_fichero_dmp IN VARCHAR2,
nombre_fichero_log IN VARCHAR2,nombre_esquema IN VARCHAR2,
resultado OUT VARCHAR2);
end xxxx_BACKUP;
/
create or replace package body xxxx_BACKUP is
-- Author : xxx
-- Purpose : Procedimientos para realizar el Backup
-- de los objetos de base de datos
-- Ejecuta un comando del sistema
FUNCTION RUN_CMD(p_cmd in varchar2) return VARCHAR2
AS
language java name 'xxxxUtil.RunThisS(java.lang.String) return VARCHAR2';
-------- EXPORT ESQUEMA --------
PROCEDURE backup_esquema (ruta_exp IN VARCHAR2, usuario IN VARCHAR2,
contrasenia IN VARCHAR2, nombre_fichero_dmp IN VARCHAR2,
nombre_fichero_log IN VARCHAR2,
nombre_esquema IN VARCHAR2, resultado OUT VARCHAR2) IS
BEGIN -- definicion del procedimiento
resultado := RUN_CMD(ruta_exp || 'exp ' || un || '/' || pw
|| ' file=' || nombre_fichero_dmp || ' consistent=Y
log=' || nombre_fichero_log || ' owner='
|| some_owner );
END;
end xxxx_BACKUP;
/
After inserting this package in my database, I've granted the next permission(i put the one i remember, maybe i have granted someone else):
Execute dbms_java.grant_permission( 'EPORTALES_R','SYS:java.io.FilePermission', '<<ALL FILES>>','execute');
The xxxx_BACKUP package is called from a java object, which is run in a web page. This is the java function which calls the xxxx_BACKUP:
public List<Object> ejecutarUpdate(String sql,
List<Object> parametersIn,
List<Integer> parametersOut)
throws SQLException {
List<Object> retorno = new ArrayList<Object>();
try {
logger.debug("ejecutarSQL - SQL: " + sql);
CallableStatement stmt = connection.prepareCall(sql);
int in = 1;
if (parametersIn != null) {
Iterator<Object> itIn = parametersIn.iterator();
while (itIn.hasNext()) {
stmt.setObject(in, itIn.next());
in++;
}
}
int out = in;
if (parametersOut != null) {
Iterator<Integer> itOut = parametersOut.iterator();
while (itOut.hasNext()) {
Integer current = itOut.next();
stmt.registerOutParameter(out, current.intValue());
out++;
}
}
stmt.executeUpdate();
connection.commit();
for (; in < out; in++) {
retorno.add(stmt.getString(in));
}
if(logger.isDebugEnabled())
{
logger.debug("La sentencia ejecutada: "+sql);
logger.debug("La sentencia ejecutada2: "+stmt);
}
} catch (SQLException e) {
logger.error("ejecutarSQL() - excepcion: " + e.getMessage(), e);
throw e;
}
return retorno;
}
The idea is to run the exp tool to export a schema. The "ejecutarUpdate" java function is located in a machine, but the schema we want to export is located in another one. This is why "ejecutarUpdate" function establishes a connection with a database. Using this connection, through the "backup_esquema" function (located in xxxx_BACKUP package), the code calls the exp tool.
With all the variables properly filled (path, user, password, etc), what i get is the next message: "can't exec: /aplicaciones/oracle/oradcli02/10.2.0/bin/exp doesn't exist". However, the exp process exist, as I`ve seen using ls command:
-rwxr-xr-x 1 oracle dba 809224 Feb 6 2008 /aplicaciones/oracle/oradcli02/10.2.0/bin/exp
To test the "xxxxUtil" object, I have done an easy test.I have run from SQLPLUS the next anonymous PL/SQL:
SET FEEDBACK ON
SET SERVEROUTPUT ON SIZE 300000
declare
cad varchar2(1000);
begin
cad := xxxx_backup.RUN_CMD('/bin/who i am');
DBMS_OUTPUT.PUT_LINE('returns '
||cad);
end;
/
The DBMS_OUTPUT.PUT_LINE returns the following: "returns 0", so I think it worked ok.
However, if if try to run this anonymous PL/SQL calling the exp tool (absolute path) instead of the who tool, I get the following: "can't exec: /aplicaciones/oracle/oradcli02/10.2.0/bin/exp doesn't exist"
What i am doing wrong?
Thanks in advanced,
Ciri
[EDITED by LF: removed certain information as per OP's request]
[Updated on: Mon, 20 July 2009 03:57] by Moderator Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sat Jan 11 15:13:01 CST 2025
|