Oracle
在 Oracle 11g 上執行 shell 腳本
我有一個 oracle 數據庫:
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production "CORE 11.2.0.1.0 Production" TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
我想執行儲存在數據庫伺服器上的腳本。
path: /d01/oracle/scripts/super_skripta.sh
我的腳本(測試腳本)的內容:
IME=$(date +"%s") touch /d01/oracle/scripts/$IME
有人可以解釋我(一步一步)如何從 oracle 數據庫執行這個腳本嗎?
我試圖創建一個這樣的可執行程序:
begin dbms_scheduler.create_program ( program_name => 'SUPER_SKRIPTA', program_type => 'EXECUTABLE', program_action => '/d01/oracle/scripts/super_skripta.sh', enabled => TRUE, comments => 'super skripta' ); end; /
然後創建一個工作:
BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => '"WOLFY"."JOB_SS"', program_name => '"WOLFY"."SUPER_SKRIPTA"', start_date => NULL, repeat_interval => NULL, end_date => NULL, enabled => FALSE, auto_drop => FALSE, comments => '', job_style => 'REGULAR'); DBMS_SCHEDULER.SET_ATTRIBUTE( name => '"WOLFY"."JOB_SS"', attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_OFF); DBMS_SCHEDULER.enable( name => '"WOLFY"."JOB_SS"'); END;
但它不起作用……
環境:
[oracle@o61 ~]$ ls -l /home/oracle/myscript* -rwxr-xr-x. 1 oracle oinstall 44 Mar 25 17:38 /home/oracle/myscript.sh [oracle@o61 ~]$ cat /home/oracle/myscript.sh #!/bin/bash touch /home/oracle/myscript.out [oracle@o61 ~]$ [oracle@o61 ~]$ ls -l $ORACLE_HOME/bin/extjob* -rwsr-x---. 1 root oinstall 1254574 Nov 1 21:01 /u01/app/oracle/product/11.2.0/dbhome_1/bin/extjob -rwx------. 1 oracle oinstall 1254574 Nov 1 21:01 /u01/app/oracle/product/11.2.0/dbhome_1/bin/extjobo -rwsr-x---. 1 root oinstall 1254292 Oct 19 14:54 /u01/app/oracle/product/11.2.0/dbhome_1/bin/extjobO -rw-------. 1 oracle oinstall 1254292 Oct 19 14:54 /u01/app/oracle/product/11.2.0/dbhome_1/bin/extjoboO [oracle@o61 ~]$ grep -v "^#" $ORACLE_HOME/rdbms/admin/externaljob.ora run_user = oracle run_group = oinstall
然後創建一個執行一次然後刪除的作業:
[oracle@o61 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 25 17:42:13 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options begin dbms_scheduler.create_job ( job_name => 'RUN_SCRIPT', job_type => 'EXECUTABLE', job_action => '/home/oracle/myscript.sh', enabled => true, auto_drop => true ); end; 11 / PL/SQL procedure successfully completed. SQL> SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@o61 ~]$ ls -l /home/oracle/myscript.* -rw-r--r--. 1 oracle oinstall 0 Mar 25 17:42 /home/oracle/myscript.out -rwxr-xr-x. 1 oracle oinstall 44 Mar 25 17:38 /home/oracle/myscript.sh [oracle@o61 ~]$