Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DBMS_SCHEDULER wait for job/program to finish

jstem1177Jan 15 2014 — edited Jan 16 2014

Hello All,

I've run into a little limitation on my understanding of DBMS_SCHEDULER.

I have an executable script which does a network scan. My goal is to lauch this from an application, and wait (could be 5 minutes or 2 hours) for the scan to finish before I return the results.

Where I'm a little confused, is the flow of the entire process works when I want to wait for the program to complete:

1 - Define a program?

2 - Apply arguments?

3 - Apply credentials

4 - Define a chain?

Literally, I'm not sure how to tackle this task. I simply wish to launch to job and wait for it to finish before I go retreive the file from the server. This is what I have so far, just bits and pieces.

Mayeb I simply missed somethign in the docs, and I'm overcomplicate things.

Thanks in advance to the community for you assistance.

Jan S.

BEGIN

 

 

  dbms_scheduler.create_program(

    program_name   => 'network_scan',

    program_type   => 'executable',

    number_of_arguments => 5,

    program_action => 'scan_network.py',

    enabled        =>  FALSE);

 

  dbms_scheduler.define_program_argument('network_scan',1,'x01=1');

  dbms_scheduler.define_program_argument('network_scan',2,'x02=192.168.1.1');

  dbms_scheduler.define_program_argument('network_scan',3,'x03=24');

  dbms_scheduler.define_program_argument('network_scan',4,'x04=D');

  dbms_scheduler.define_program_argument('network_scan',5,'x05=1521-1523,7777'); 

  vJobName := dbms_scheduler.generate_job_name('NET_SCAN_');

 

  dbms_scheduler.create_job(job_name => vJobName,

                              job_type => 'EXECUTABLE',

                              job_action => '/usr/bin/scan_nework.sh',

                              number_of_arguments => 5,

                              enabled => FALSE,

                              auto_drop => FALSE,

                              comments => 'Network');

dbms_scheduler.set_attribute(vJobName,'credential_name', 'SUCREDENTIALS');

  dbms_scheduler.run_job(vJobName,FALSE);

 

  dbms_scheduler.create_chain (

   chain_name            =>  'net_scan_chain',

   rule_set_name         =>  NULL,

   evaluation_interval   =>  NULL,

   comments              =>  NULL);

 

  dbms_scheduler.define_chain_step('net_scan_chain', 'step1', 'network_scan');

 

  SELECT additional_info, external_log_id

  INTO   l_additional_info, l_external_log_id

  FROM   (SELECT log_id,

                 additional_info,

                 REGEXP_SUBSTR(additional_info,'job[_0-9]*') AS external_log_id

          FROM   dba_scheduler_job_run_details

          WHERE  job_name = vJobName

          ORDER BY log_id DESC)

  WHERE  ROWNUM = 1;

  DBMS_OUTPUT.put_line('ADDITIONAL_INFO: ' || l_additional_info);

  DBMS_OUTPUT.put_line('EXTERNAL_LOG_ID: ' || l_external_log_id); 

 

 

   

  -- Wait at least 3 second because its distributed

  dbms_lock.sleep(3);

  SELECT job_name, status, error#, additional_info

  FROM dba_scheduler_job_run_details

  WHERE job_name= vJobName;

  

 

  dbms_lob.createtemporary(l_clob, FALSE);

  dbms_scheduler.get_file(

    source_file     => l_external_log_id ||'_stdout',

    credential_name => 'ORACLECREDENTIALS',

    file_contents   => l_clob,

    source_host     => NULL);

  DBMS_OUTPUT.put_line('stdout:');

  DBMS_OUTPUT.put_line(l_clob);

k Scan');

This post has been answered by unknown-7404 on Jan 15 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2014
Added on Jan 15 2014
2 comments
2,248 views