Scheduling exe to run in a job with Oracle 10

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.
kiss98770Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sathyagiriCommented:
Check the permission on your exe.Check the log history to see if you can find any info there
0
schwertnerCommented:
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
kiss98770Author Commented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

schwertnerCommented:
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
kiss98770Author Commented:
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
schwertnerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kiss98770Author Commented:
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
schwertnerCommented:
Seems it is a Windows problem.
Try to find solution either using Google
or posting a question in the Windows thread.
0
kiss98770Author Commented:
Thanks for your help with the java procedures!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.