Solved

Scheduling exe to run in a job with Oracle 10

Posted on 2007-03-20
9
544 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
 
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
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.

 

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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Oracle PL/SQL syntax 4 52
PL/SQL Two PAYER_IDs with PAYER_TYPES these two types 4 26
null value 15 62
Oracle Subquery bad Join 11 43
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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 how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now