1
 declare
      vname varchar(20) := 'DEMOJOB';
    BEGIN
      begin dbms_scheduler.drop_job (vname); exception when others then null; end ;
      dbms_scheduler.create_job(
        job_name => vname,
        job_type => 'EXECUTABLE',
        job_action => 'D:\Version_Start\PSTools\psexec64.exe \\server1 -u test-domain\usr1 -p Tes_@23 -i -d D:\Start_OC4J.bat',
        number_of_arguments => 0,
       enabled => FALSE); 
     dbms_scheduler.enable( vname);
 
   END;
  /

the error which i'm getting is ORA-27369: job of type EXECUTABLE failed with exit code: Incorrect function.

Sha
  • 11
  • 2
  • Does it finish successfully when you execute the same command in the CMD? – astentx Jan 11 '23 at 10:00
  • @astentx yes from command prompt it works fine – Sha Jan 11 '23 at 10:03
  • I don't usually like to throw out random ideas, but when it comes to combining DBMS_SCHEDULER and OS commands, the error messages are often not helpful and I just try different variations of the code. First, in case there's some permission issue, try running the job as SYS. (Just to narrow down the problem - don't eternally run code as SYS.) Also, instead of putting everything in the JOB_ACTION, try calling just the executable and adding the arguments like `dbms_scheduler.set_job_argument_value(vname, 1, '\\server1');`. – Jon Heller Jan 12 '23 at 05:28
  • @JonHeller tried both options but same error happens – Sha Jan 12 '23 at 05:38

1 Answers1

0

That is not how you run a program with multiple arguments in the scheduler. You need to set arguments individually. For example to run an old "exp" command you would do

SQL> exec DBMS_SCHEDULER.CREATE_JOB(JOB_NAME => 'CONNOR_JOB',JOB_TYPE => 'EXECUTABLE',JOB_ACTION =>'c:\oracle\product\12.1.0.2\bin\exp.exe', NUMBER_OF_ARGUMENTS => 4);

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('CONNOR_JOB', 1, 'userid=connor/connor@np12');

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('CONNOR_JOB', 2, 'file="c:\temp\dump.dmp"');

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('CONNOR_JOB', 3, 'owner=scott');

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE('CONNOR_JOB', 4, 'log="c:\temp\CONNOR_JOB.log"');

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.RUN_JOB(JOB_NAME => 'CONNOR_JOB', USE_CURRENT_SESSION => TRUE);

PL/SQL procedure successfully completed.

SQL> select job_name, status from user_scheduler_job_run_details order by log_date;

JOB_NAME                       STATUS
------------------------------ ------------------------------
CONNOR_JOB                     SUCCEEDED

In your case, I'd recommend storing a CMD file with all the bits and pieces you need and then just call that. Keeps things simple. If you need to dynamically create the CMD script, just use UTL_FILE to write it.

Connor McDonald
  • 10,418
  • 1
  • 11
  • 16
  • I need to run a batch file located on a remote server using the psexec tool. I have tried setting the arguments individually but it is not working. – Sha Jan 13 '23 at 12:34
  • What happens if you write "D:\Version_Start\PSTools\psexec64.exe \\server1 -u test-domain\usr1 -p Tes_@23 -i -d D:\Start_OC4J.bat" to a local command file and run that? – Connor McDonald Jan 14 '23 at 06:47
  • it works fine if i write on a local command file and run it. – Sha Jan 16 '23 at 05:49