Forum Stats

  • 3,827,131 Users
  • 2,260,743 Discussions


Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files

Rnr-Oracle Member Posts: 1,269 Employee
edited May 28, 2013 6:48AM in Scheduler

NOTE: Users using 11g should use the new method of specifying a credential which eliminates many of the issues mentioned in this note.

This guide covers several common questions and problems encountered when using
dbms_scheduler to run external jobs, either on Windows or on UNIX.

What operating system (OS) user does the job run as ?

External jobs which have a credential (available in 11g) run as the user
specified in the credential. But for jobs without credentials including
all jobs in 10gR1 and 10gR2 there are several cases.

- On UNIX systems, in releases including and after there is a file $ORACLE_HOME/rdbms/admin/externaljob.ora . All external jobs not in the SYS schema and with no credential run as the user and group specified in this file. This should be nobody:nobody by default.

- On UNIX systems, in releases prior to there was no "externaljob.ora" file. In this case all external jobs not in the SYS schema and with no credential run as the owner and group of the $ORACLE_HOME/bin/extjob file which should be setuid and setgid. By default extjob is owned by nobody:nobody except for oracle-xe where it is owned by oracle:oraclegroup and is not setuid/setgid.

- On Windows, external jobs not in the SYS schema and with no credential run as the user that the OracleJobScheduler Windows service runs as. This service must be started before these jobs can run.

- In all releases on both Windows and UNIX systems, external jobs in the SYS schema without a credential run as the oracle user.

What errors are reported in SCHEDULERJOB_RUN_DETAILS views ?

If a job fails, the first place to look for diagnostic information is the SCHEDULERJOB_RUN_DETAILS set of views. In 10gR2 and up the first 200 characters of the standard error stream is included in the additional_info column.

In all releases, the error number returned by the job is converted into a
system error message (e.g. errno.h on UNIX or net helpmsg on Windows) and that
system error message is recorded in the additional info column. If there is no
corresponding message the number is displayed.

In 11g and up the error number returned by the job is additionally recorded in
the error# column. In earlier releases 27369 would always be recorded in the
error# column.

Generic Issues Applicable to UNIX and Windows

- The job action (script or executable) must return 0 or the job run will be marked as failed.

- Always use the full pathname to executables and scripts.

- Do not count on environment variables being set in your job. Make sure that the script or executable that your jobs runs sets all required environment variables including ORACLE_HOME, ORACLE_SID, PATH etc.

- It is not recommended to pass in a complete command line including arguments as the action. Instead it is recommended to pass in only the path to and name of the executable and to pass in arguments as job argument values.

- Scripts with special characters in the execution path or script name may give problems.

- Ensure that the OS user your job runs as has the required privileges/permissions to run your job. See above for how to tell who the job runs as.

- External job actions cannot contain redirection operators e.g. > < >> | && ||

- In general try getting a simple external job working first e.g. /bin/echo or ipconfig.exe on Windows. Also try running the job action directly from the commandline as the OS user that the job will run as.

Windows-specific Issues

- The OracleJobScheduler Windows service must be started before external jobs will run (except for jobs in the SYS schema and jobs with credentials).

- The user that the OracleJobScheduler Windows service runs as must have the "Log on as batch job" Windows privilege.

- A batch file (ending in .bat) cannot be called directly by the Scheduler. Instead cmd.exe must be used and the name of the batch file passed in as an argument. For example
job_type=>'executable', enabled=>false);
- In 10gR1 external jobs that wrote to standard output or standard error streams would sometimes return errors. Redirect to files or suppress all output and error messages when using 10gR1 to run external jobs.

UNIX-specific Issues

- When running scripts, make sure that the executable bit is set.

- When running scripts directly, make sure that the first line of the script in a valid shebang line - starting with "#!" and containing the interpreter for the script.

- In release, jobs creating a large amount of standard error text may hang when running (this was fixed in the first patchset). If you are seeing this issue, redirect standard error to a file in your job. This issue has been seen when running the expdp utility which may produce large amounts of standard error text.

- the user that the job runs as (see above section) must have execute access on $ORACLE_HOME/bin and all parent directories. If this is not the case the job may be reported as failed or hang in a running state. For example if your $ORACLE_HOME is /opt/oracle/db then you would have to make sure that

chmod a+rx /opt
chmod a+rx /opt/oracle
chmod a+rx /opt/oracle/db
chmod a+rx /opt/oracle/db/bin

- On oracle-xe, the primary group of your oracle user (if it exists) must be dba before you install oracle-xe for external jobs to work. If you have an oracle user from a regular Oracle installation it may have the primary group set to oinstall.

- On oracle-xe, the extjobo executable is missing so external jobs in the SYS schema will not work properly. This can be fixed by copying the extjob executable to extjobo in the same directory ($ORACLE_HOME/bin).

- Check that correct permissions are set for external job files - extjob and externaljob.ora (see below)

Correct permissions for extjob and externaljob.ora on UNIX

There is some confusion as to what correct permissions are for external job related files.

In 10gR1 and :

- rdbms/admin/externaljob.ora should not exist

- bin/extjob should be setuid and setgid 6550 (r-sr-s---). It should be owned by the user that jobs should run as and by the group that jobs should run as.

- bin/extjobo should have normal 755 (rwxr-xr-x) permissions and be owned by oracle:oraclegroup

In and higher

- rdbms/admin/externaljob.ora file must must be owned by root:oraclegroup and be writable only by the owner i.e. 644 (rw-r--r--) It must contain at least two lines: one specifying the run-user and one specifying the run-group.

- bin/extjob file must be also owned by root:oraclegroup but must be setuid i.e. 4750 (-rwsr-x---)

- bin/extjobo should have normal 755 (rwxr-xr-x) permissions and be owned by oracle:oraclegroup

In 11g and higher

Same as but additionally bin/jssu should exist with root setuid
permissions i.e. owned by root:oraclegroup with 4750 (-rwsr-x---)

Internal Error numbers for UNIX on or or higher

If you are not using a credential and are using version or higher or or higher you may come across an internal error number. Here are the meanings for the internal error numbers.

274661 - can't get owner of or permissions of externaljob.ora file
274662 - not running as root or externaljob.ora file is writable by group or other or externaljob.ora file not owned by root (can't switch user)
274663 - setting the group or effective group failed
274664 - setting the user or effective user failed
274665 - a user or group id was not changed successfully
274666 - cannot access or open externaljob.ora file
274667 - invalid run_user specified in externaljob.ora file
274668 - invalid run_group specified in externaljob.ora file
274669 - error parsing externaljob.ora file
274670 - extjobo is running as root user or group


  • 547817
    547817 Member Posts: 72
    Thanks Ravi. this is helpful.
    i got a question and a remark.

    is it possible to fetch the standard output from the program (not error message, just standard output) ?

    if i recall correctly calling a batch file from an external job does not require using the full path to CMD.exe, executing standard cmd commands such as COPY and DEL does require the full path.
  • Rnr-Oracle
    Rnr-Oracle Member Posts: 1,269 Employee

    In 11g, using the new method of executing an external job (using a credential) it is possible to retrieve the job output using the dbms_scheduler.get_file command. In 10g or using the old method (without a credential) it is not possible to retrieve the job output and you would need to redirect the output to a file to see it.

    I know that lots of people have seen errors when running batch scripts directly (which went away when using cmd.exe), but I guess it is possible that some Windows configurations allow it.

  • 571582
    571582 Member Posts: 110
    Hi Ravi,

    Can you help me...

    Hi All,

    I planned to create a job to do rman backup daily at 04:00 AM.
    1. I created a program as follows
    program_name => 'rman_backup_prg',
    program_action => '/u02/rmanback/',
    program_type => 'EXECUTABLE',
    comments => 'RMAN BACKUP');

    my rman script is

    export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    export PATH=$PATH:/u01/app/oracle/product/10.2.0/db_1/bin
    /u01/app/oracle/product/10.2.0/db_1/bin/exp rman/[email protected] file=/u02/rmanback/rm
    an_220108.dmp log=/u02/rmanback/rman_220108.log owner=rman statistics=none comp
    ress=n buffer=400000
    compress *.dmp

    2. I created a schedule as follows

    schedule_name => 'rman_backup_schedule',
    start_date => SYSTIMESTAMP,
    end_date => '31-DEC-16 05.00.00 AM',
    repeat_interval => 'FREQ=DAILY; BYHOUR=4',
    comments => 'Every day at 4 am');

    3. I created ajob as follows.

    job_name => 'rman_backup_job',
    program_name => 'rman_backup_prg',
    schedule_name => 'rman_backup_schedule',
    enabled=> true,
    auto_drop=> false

    While I am running the job I am getting the following error anybody help me.

    ORA-27369: job of type EXECUTABLE failed with exit code: Not owner
    ORA-06512: at "SYS.DBMS_ISCHED", line 150
    ORA-06512: at "SYS.DBMS_SCHEDULER", line 441
    ORA-06512: at line 2

    If I removed "compress *.dmp" line in rman script it is working fine.

    /* additional Info from dba_scheduler_job_run_details as follows */
    ORA-27369: job of type EXECUTABLE failed with exit code: Not owner
    Export: Release - Production on Tue Jan 22 14:30:08 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Release - Production

  • Rnr-Oracle
    Rnr-Oracle Member Posts: 1,269 Employee
    Hi Kiran,

    Try specifying the complete path to compress e.g. /usr/bin/compress
    Also try cd'ing to the correct directory first
    Also try redirecting all output to a file and then taking a look at the file afterwards to see any errors.


    cd /u02/rmanback
    /usr/bin/compress *.dmp >> /tmp/backup.log

    Hope this helps,
  • 571582
    571582 Member Posts: 110
    Hi Ravi,

    Thank you very much.

    Its worked.

  • 571582
    571582 Member Posts: 110
    Hi Ravi,

    For oracle, Is it supports for scheduler jobs with action type 'EXECUTABLE'

  • Rnr-Oracle
    Rnr-Oracle Member Posts: 1,269 Employee

    Yes external jobs are supported on on all platforms except AIX.

  • 445103
    445103 Member Posts: 157

    While working with scheduler and external jobs on 11g I have encoutered error:
    SQL> exec DBMS_SCHEDULER.run_job('FTJOB');

    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    Process ID: 31854
    Session ID: 295 Serial number: 20

    - from trace fie:

    Exception [type: SIGSEGV, Address not mapped to object] [ADDR:0xC8] [PC:0x1218199, Exception [type: SIGSEGV, Address not
    mapped to object] [ADDR:0xC8] [PC:0x1218199, jslve_execute0()+3927]
    Incident 24154 created, dump file: /opt/oracle/diag/rdbms/stat/stat/incident/incdir_24154/stat_ora_31652_i24154.trc
    ORA-07445: exception encountered: core dump [jslve_execute0()+3927] [SIGSEGV] [ADDR:0xC8] [PC:0x1218199] [Address not mapped to object] []

    ssexhd: crashing the process...
    Shadow_Core_Dump = partial

    It sounds like a bug?
    Did anyone else have encoutered similar error?

  • Rnr-Oracle
    Rnr-Oracle Member Posts: 1,269 Employee
    Hi Goran,

    Yes an Oracle crash is almost always a bug and this does look like a bug. Can you post a test case here and/or file it through your support rep as a bug ?

  • 631010
    631010 Member Posts: 2
    edited Mar 28, 2008 11:07AM
    Hi Ravi,

    could you post the correct configuration for too?

    I got a little desperate trying to get a simple shell to run. More complex stuff (actually calling sqlldr with a bunch of parameters) will come later on.

    Here's what I try to do:

    end; is
    /bin/echo `/bin/date` >> mist

    Checking status:
    select error#,status,additional_info from DBA_SCHEDULER_JOB_RUN_DETAILS
    where job_name='TEST1';

    Initially all results were:
    27370 FAILED ORA-27370: Job-Unterprozess konnte einen Job vom Typ EXECUTABLE nicht starten
    ORA-27300: BS-abhängiger Vorgang accessing execution agent mit Status: 2 nicht erfolgreich
    ORA-27301: BS-Fehlermeldung: No such file or directory
    ORA-27302: Fehler aufgetreten bei: sjsec 3

    Everything seemed right, the shell exists, permissions are set, no paths used in the shell, etc. After a long search through the web and reading this thread I discovered that bin/extjob was missing. I made the admins copy bin/extjob.nobody and set the permissions you recommended (is that documented anywhere?). Now at least the error message is different, so I suspect the oracle configuration might be misconfigured:

    27369 FAILED ORA-27369: Job vom Typ EXECUTABLE nicht erfolgreich mit Exit-Code: 274668
    STANDARD_ERROR="Oracle Scheduler error: Invalid or missing run_group in configuration file."

    What's the next step to fix the problem? My guess is to mess with the rdbms/admin/externaljob.ora file - but what is expected? I didn't find anything useful on tahiti.

This discussion has been closed.