ORACLE 12C – run external script
In earlier releases running a shell script from the scheduler was difficult.
In release 11g, to run a shell script one had to create an external job that launches the command interpreter, and pass through the script as a command line argument.
In release 12c Oracle has improved the DBMS_SCHEDULER package functionality adding some interesting new features. One of this new features is the capability to run external scripts as part of our job action or even better the capability to write our own custom scripts and run them by invoking the shell interpreter (in case of unix environments) or the command prompt (in windows environments). This custom script can be directly writed inside the job definition.
This new job type is named ‘EXTERNAL_SCRIPT’. This definition specifies that the job is an external script that uses the command shell of the computer running the job.
The external_script job type:
- script_file varchar2(32000) ;/
- script_file := ‘#!/bin/bash
- export PATH=$PATH:/bin
- cd /tmp
- mkdir external
- cd external
- touch prova.txt’;
- job_name => ‘EXTJOB’,
- job_type => ‘EXTERNAL_SCRIPT’,
- job_action => script_file,
- credential_name => ‘oracle_os_credentials’,
- enabled => TRUE);
PL/SQL procedure successfully completed.
On the database verify execution result:
SQL> SELECT job_name,
- to_char(log_date,’yyyy-mm-dd hh24:mi’) log_date
- FROM user_scheduler_job_run_details
- ORDER BY 1;
JOB_NAME STATUS ERROR# LOG_DATE
————— ——————- ———– ———————
EXTJOB SUCCEEDED 0 2015-06-08 14:28
On the operation system verify execution result:
[oracle@ora12c ~]$ cd /tmp/external
[oracle@ora12c external]$ ls -l
-rw-rw-rw- 1 oracle oinstall Jun 08 14:28 prova.txt