Solved

Scheduling exe to run in a job with Oracle 10

Posted on 2007-03-20
9
556 Views
Last Modified: 2013-12-19
I am trying to set up an Oracle 10 scheduled job containing 2 steps.   The first step is to run a stored procedure and the second step is to run an exe program.

I've set the schedule up using Oracle Enterprise Manager.   The job starts and runs the first step successfully.    However, the second step just sits there...it doesn't say stalled and CPU used (seconds) stays 0.

Any idea what I could be missing why my exe isn't starting to run?   Is there a better way to schedule this job?

Thanks for your help.
0
Comment
Question by:kiss98770
  • 4
  • 4
9 Comments
 
LVL 14

Expert Comment

by:sathyagiri
ID: 18762076
Check the permission on your exe.Check the log history to see if you can find any info there
0
 
LVL 47

Expert Comment

by:schwertner
ID: 18762750
I do not know a direct way to do this.
One workaround is to use Java in PL/SQL procedure

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:952229840241
0
 

Author Comment

by:kiss98770
ID: 18772049
I found I didn't have the external job schedule service enabled so I've made that change.   I'm still hoping I can use Oracle job scheduler to do this.

However, now my exe does get submitted (I can see it in windows task manager) but it just sits there.  It's not doing any processing (which I can tell from the log file).     The CPU sits at 0%.   If I just click on my pgm to run, it starts and finishes immediately.   Submitting it through the scheduler, it seems to hang.

Any ideas?
Thanks for all your help.
0
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.

 
LVL 47

Expert Comment

by:schwertner
ID: 18772295
It is not so easy or wasn't.

You can issue unix commands from within a pl/sql procedure if you have oracle 8i or up. do the following:

insert this java procedure into the database:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "HOST" AS
import java.lang.*;
import java.io.*;

public class Host
{
 public static void executeCommand (String command, String etype) throws IOException
 {
   String[] wFullCommand = {"C:\\winnt\\system32\\cmd.exe", "/y", "/c", command};
   String[] uFullCommand = {"/bin/sh", "-c", command};
   if (etype.toUpperCase().equals("W"))
     Runtime.getRuntime().exec(wFullCommand);
   else if(etype.toUpperCase().equals("U+"))
     Runtime.getRuntime().exec(uFullCommand);
   else if(etype.toUpperCase().equals("U"))
     Runtime.getRuntime().exec(command);
 }
};
/

now compile this pl/sql wrapper procedure in the database:

CREATE OR REPLACE PROCEDURE Host_Command_Proc (p_command  IN  VARCHAR2, p_etype  IN  VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String, java.lang.String)';
/

to issue a unix command to remove all files from a directory for example, you would put this line in your pl/sql procedure:

host_command_proc ('cd home/yourdir/another_dir', 'U+');
host_command_proc ('rm -f *', 'U+');

**note: for this to work you must have the correct java classes loaded in the database.
0
 

Author Comment

by:kiss98770
ID: 18780630
Hi!

Thanks for those procedures!    I  loaded them and I tried running my 'exe'.    I found my pgm does get loaded and I can see it in Task Manager.   But,  it's not really processing or doing anything.   Normally, if I run my pgm manually, it's just a few seconds and it's done.

Any ideas what I need to do to get job moving?

Thanks so much for your help.
0
 
LVL 47

Accepted Solution

by:
schwertner earned 500 total points
ID: 18781046
Seems you have to grant some permissions for executing.
See this:

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:952229840241
I'm looking for a Java-procedure executing host calls on a Unix environment from
the Oracle-server.
Here is how to do this in java in 8.1.6.  8.1.6 added lots of new security
features so this would be a little different in 8.1.5 but mostly the same.  

We need to start by granting some privs.  I'm going to grant as little as I have
to get allow us to execute the program /usr/bin/ps.  As SYS or some
appropriately priveleged user, we will execute:

sys@DEV816> begin
  2      dbms_java.grant_permission
  3      ('RT_TEST',
  4       'java.io.FilePermission',
  5       '/usr/bin/ps',
  6       'execute');
  7  
  8      dbms_java.grant_permission
  9      ('RT_TEST',
 10       'java.lang.RuntimePermission',
 11       '*',
 12       'writeFileDescriptor' );
 13  end;
 14  /

PL/SQL procedure successfully completed.


That allows our user RT_TEST to successfully execute that program.  We could
have allowed it to execute /usr/bin/* or * or whatever -- I'm just letting it
execute that one program.

Now, RT_TEST would create in its schema:


rt_test@DEV816> create or replace and compile
  2  java source named "Util"
  3  as
  4  import java.io.*;
  5  import java.lang.*;
  6  
  7  public class Util extends Object
  8  {
  9  
 10    public static int RunThis(String[] args)
 11    {
 12    Runtime rt = Runtime.getRuntime();
 13    int        rc = -1;
 14  
 15    try
 16    {
 17       Process p = rt.exec(args[0]);
 18  
 19       int bufSize = 4096;
 20       BufferedInputStream bis =
 21        new BufferedInputStream(p.getInputStream(), bufSize);
 22       int len;
 23       byte buffer[] = new byte[bufSize];
 24  
 25       // Echo back what the program spit out
 26       while ((len = bis.read(buffer, 0, bufSize)) != -1)
 27          System.out.write(buffer, 0, len);
 28  
 29       rc = p.waitFor();
 30    }
 31    catch (Exception e)
 32    {
 33       e.printStackTrace();
 34       rc = -1;
 35    }
 36    finally
 37    {
 38       return rc;
 39    }
 40    }
 41  }
 42  /

Java created.

rt_test@DEV816> create or replace
  2  function RUN_CMD( p_cmd  in varchar2) return number
  3  as
  4  language java
  5  name 'Util.RunThis(java.lang.String[]) return integer';
  6  /

Function created.


To make this callable as a procedure (ignoring the return code), we'll create a
procedure:

rt_test@DEV816>
rt_test@DEV816> create or replace procedure RC(p_cmd in varchar2)
  2  as
  3    x number;
  4  begin
  5    x := run_cmd(p_cmd);
  6  end;
  7  /

Procedure created.

And now to run it:

rt_test@DEV816> set serveroutput on size 1000000
rt_test@DEV816> exec dbms_java.set_output(1000000)
PL/SQL procedure successfully completed.
rt_test@DEV816> exec rc('/usr/bin/ps -ef');
UID   PID  PPID  C    STIME TTY      TIME CMD
root     0     0  0   Aug 17 ?        0:06 sched
root     1     0  0   Aug 17 ?        1:19 /etc/init -
root     2     0  0   Aug 17 ?        0:23 pageout
.....

PL/SQL procedure successfully completed.

rt_test@DEV816>
0
 

Author Comment

by:kiss98770
ID: 18781686
I've granted the securities.   But, my job still just sits there not processing.  I also thought if I had a security problem, my job would fail because of that.    But from windows task manager, I can see it there and CPU is at 0%....nothing is happening.   The job has been submitted but it doesn't seem to be active.

Thanks for much for helping me work through this.
0
 
LVL 47

Expert Comment

by:schwertner
ID: 18791353
Seems it is a Windows problem.
Try to find solution either using Google
or posting a question in the Windows thread.
0
 

Author Comment

by:kiss98770
ID: 18792627
Thanks for your help with the java procedures!
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

Title # Comments Views Activity
C# Connection String for Oracle database is not working 22 144
automatic email alert 1 52
Migrate Oracle Database from ASM to Non-ASM on a Windows server. 1 45
SQL Developer 6 48
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

777 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