This content has been marked as final. Show 2 replies
You can refer to below blog for more clarification and examples.
@sushaant - the post you refer to has no relevance to using DBMS_SCHEDULER - it is just using a cron job to run a shell script.
@Ramu - if the shell script is on the same server as the oracle database, you need to do the following
1) Create a credential that has the unix user you want to run the script as.
Note the script itself MUST set up any environment needed for the job to run - DBMS_SCHEDULER will not execute the .profile of the user you supply in the credential so don't assume in run.sh that any $PATH will exist or any other environment variables, you must set these explicitly. E.g. if you use a unix command, you should ensure you specify the full path to it in run.sh.
DBMS_SCHEDULER.CREATE_CREDENTIAL('YOUR_CREDENTIAL', 'username', 'password');
2) In sqlplus, create a job with an external job that references run.sh and add argument. Change yourjob to be the job name
you want to see when the job runs and your_table_name to the table that should be used in this particular job.
4) Create a job which links the program to the schedule and runs daily at midday and create other jobs for other tables giving them different parameters. If you have several of these to run but don't want them to run at the same time, look at the CREATE_CHAIN commands in the Oracle 11gR2 database admin guide as there are two whole chapters (28 & 29) on the scheduler ( http://docs.oracle.com/cd/E11882_01/server.112/e25494/scheduse.htm#i1033533 )
job_name => 'run_tablename1',
program_name => 'yourprogram',
repeat_interval => 'FREQ=DAILY;BYHOUR=12',
credential_name => 'YOUR_CREDENTIAL',
comments => 'Daily at noon');
dbms_scheduler.set_job_argument_value@orl1(job_name=>'run_tablename1', argument_position=>1, argument_value='your_table_name');
Note that as you are passing a table_name to the run.sh, i'm guessing it might be running some Oracle commands such as an analyse so if run.sh contains PLSQL commands, you could create a PLSQL package or procedure in the database and instead of creating an external program that runs a shells script, just run the PLSQL directly from DBMS_SCHEDULER. This is simpler as you don't need to create credentials etc.. needed for an external program.
job_name => 'yourname',
job_type => 'STORED_PROCEDURE',
job_action => 'YOUR_PKG.DO_STUFF',
start_date => '18-MAY-13 12.00.00 AM',
repeat_interval => 'FREQ=DAILY', /* every day */
end_date => '17-MAY-14 12.00.00 AM',
auto_drop => FALSE,
comments => 'My new job');
and again create a chain if you want to run several when one completes.
You need to select from various tables to see the result of the jobs and whether they succeed or not such as
select * From user_scheduler_job_run_details where job_Name='run_tablename1'
SELECT * FROM USER_SCHEDULER_JOB_LOG;
select * from user_scheduler_running_jobs
You can add email notifications using DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION
See the admin guide for more details.