Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scheduling exe to run in a job with Oracle 10

Posted on 2007-03-20
9
Medium Priority
?
585 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 48

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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 48

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 48

Accepted Solution

by:
schwertner earned 2000 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 48

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

[Webinar] Protection from Cyberattacks

In this session, we’ll dive into the complexities of modern cyber threats and why only multi-vector protection can keep today’s businesses secure through the various stages of a cyberattack, across multiple vectors. Thursday September 14, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

730 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