dbms_scheduler 执行shell script

A simple dummy example to validate this:
 

rm /tmp/mylog_*.log
echo '#!/bin/ksh' > /tmp/test.sh
echo 'DATE=`date +%Y%m%d`' >> /tmp/test.sh
echo 'echo "this is a test " > /tmp/mylog_$DATE.log' >> /tmp/test.sh
sqlplus /nolog << EOF

connect / as sysdba
exec dbms_scheduler.drop_job('MY_JOB');
exec dbms_scheduler.drop_credential('MY_CRED');
exec dbms_scheduler.create_credential('MY_CRED','oracle','oracle1');

begin
dbms_scheduler.create_job(
job_name => 'MY_JOB',
job_type => 'EXECUTABLE',
job_action => '/tmp/test.sh',
auto_drop => FALSE,
enabled => false,
comments => 'Run shell-script');
end;
/
exec dbms_scheduler.Set_Attribute('MY_JOB', 'credential_name', 'MY_CRED' );
exec dbms_scheduler.enable('MY_JOB');
-- failure with wrong credentials
exec dbms_scheduler.run_job('MY_JOB');
-- fixing the credentials
exec DBMS_SCHEDULER.SET_ATTRIBUTE(name=>'MY_CRED',attribute=>'password',value=>'oracle');
-- run successfully
exec dbms_scheduler.run_job('MY_JOB');

-----??

SQL> exec DBMS_SCHEDULER.SET_ATTRIBUTE(name=>'MY_CRED',attribute=>'passfword',value=>'oracle');
begin DBMS_SCHEDULER.SET_ATTRIBUTE(name=>'MY_CRED',attribute=>'passfword',value=>'oracle'); end;

ORA-27469: PASSFWORD is not a valid credential attribute
ORA-06512: at "SYS.DBMS_ISCHED", line 3246
ORA-06512: at "SYS.DBMS_SCHEDULER", line 3150
ORA-06512: at line 1

你可能感兴趣的:(oracle)