{"id":650,"date":"2012-03-10T23:16:37","date_gmt":"2012-03-10T15:16:37","guid":{"rendered":"https:\/\/yangtingkun.net\/?p=650"},"modified":"2012-03-13T00:27:40","modified_gmt":"2012-03-12T16:27:40","slug":"%e5%88%a9%e7%94%a8scheduler%e8%b0%83%e7%94%a8shell%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/yangtingkun.net\/?p=650","title":{"rendered":"\u5229\u7528SCHEDULER\u8c03\u7528shell\u811a\u672c"},"content":{"rendered":"<p>10g\u7684SCHEDULER\u7684\u4e00\u4e2a\u91cd\u8981\u7684\u529f\u80fd\u662f\u53ef\u4ee5\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u547d\u4ee4\u6216SHELL\u811a\u672c\u3002\u800c\u572810g\u4ee5\u524d\uff0c\u8fd9\u4e2a\u529f\u80fd\u53ea\u80fd\u901a\u8fc7\u5916\u90e8\u5b58\u50a8\u8fc7\u7a0b\u6765\u5b9e\u73b0\u3002<br \/>\n\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u9996\u5148\u7f16\u8f91\u4e00\u4e2atest.sh\u811a\u672c\uff1a<\/p>\n<pre lang='SQL'>#!\/usr\/bin\/ksh\r\necho abc >> \/home\/xxx\/a.txt<\/pre>\n<p>\u6ce8\u610f\uff0c#!\/usr\/bin\/ksh\u662f\u5fc5\u987b\u7684\uff0c\u5426\u5219JOB\u8fd0\u884c\u4f1a\u51fa\u73b0ORA-27369\u9519\u8bef\u3002<br \/>\n\u7ed9\u8fd9\u4e2ashell\u8bbe\u7f6e\u6267\u884c\u6743\u9650\uff1a<\/p>\n<pre lang='SQL'>$ chmod 744 test.sh<\/pre>\n<p>\u4e0b\u9762\u5c31\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u4e2d\u5efa\u7acbPROGRAM\uff1a<\/p>\n<pre lang='SQL'>SQL> BEGIN\r\n  2     DBMS_SCHEDULER.CREATE_JOB(\r\n  3             JOB_NAME => 'J_TEST', \r\n  4             JOB_TYPE => 'EXECUTABLE', \r\n  5             JOB_ACTION => '\/home\/xxx\/test.sh', \r\n  6             ENABLED => TRUE, \r\n  7             AUTO_DROP => TRUE);\r\n  8  END;\r\n  9  \/\r\nPL\/SQL procedure successfully completed.\r\nSQL> SELECT * FROM DBA_SCHEDULER_JOBS WHERE JOB_NAME = 'J_TEST';\r\nno rows selected\r\nSQL> COL JOB_NAME FORMAT A30\r\nSQL> SELECT TO_CHAR(LOG_DATE, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM'), \r\n  2     JOB_NAME, \r\n  3     STATUS\r\n  4  FROM DBA_SCHEDULER_JOB_RUN_DETAILS\r\n  5  WHERE JOB_NAME = 'J_TEST';\r\nTO_CHAR(LOG_DATE,'YYYY-MM-DDHH24:MI: JOB_NAME                       STATUS\r\n------------------------------------ ------------------------------ ----------------------\r\n2012-03-12 18:41:16.275361 +08:00    J_TEST                         SUCCEEDED<\/pre>\n<p>\u68c0\u67e5shell\u8fd0\u884c\u4fe1\u606f\uff1a<\/p>\n<pre lang='SQL'>SQL> EXIT\r\nDisconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production\r\nWith the Partitioning, OLAP, Data Mining and Real Application Testing options\r\n[xxx@hpserver2 ~]$ more a.txt \r\nabc\r\n[xxx@hpserver2 ~]$ ls -l a.txt \r\n-rw-r--r-- 1 xxx oinstall 4 Mar 12 18:41 a.txt<\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u64cd\u4f5c\u7cfb\u7edf\u547d\u4ee4\u7684\u8c03\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>10g\u7684SCHEDULER\u7684\u4e00\u4e2a\u91cd\u8981\u7684\u529f\u80fd\u662f\u53ef\u4ee5\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u547d\u4ee4\u6216SHELL\u811a\u672c\u3002\u800c\u572810g\u4ee5\u524d\uff0c\u8fd9\u4e2a\u529f\u80fd\u53ea\u80fd\u901a\u8fc7\u5916\u90e8\u5b58\u50a8\u8fc7\u7a0b\u6765\u5b9e\u73b0\u3002 \u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u9996\u5148\u7f16\u8f91\u4e00\u4e2atest.sh\u811a\u672c\uff1a #!\/usr\/bin\/ksh echo abc >> \/home\/xxx\/a.txt \u6ce8\u610f\uff0c#!\/usr\/bin\/ksh\u662f\u5fc5\u987b\u7684\uff0c\u5426\u5219JOB\u8fd0\u884c\u4f1a\u51fa\u73b0ORA-27369\u9519\u8bef\u3002 \u7ed9\u8fd9\u4e2ashell\u8bbe\u7f6e\u6267\u884c\u6743\u9650\uff1a $ chmod 744 test.sh \u4e0b\u9762\u5c31\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u4e2d\u5efa\u7acbPROGRAM\uff1a SQL> BEGIN 2 DBMS_SCHEDULER.CREATE_JOB( 3 JOB_NAME => &#8216;J_TEST&#8217;, 4 JOB_TYPE => &#8216;EXECUTABLE&#8217;, 5 JOB_ACTION => &#8216;\/home\/xxx\/test.sh&#8217;, 6 ENABLED => TRUE, 7 AUTO_DROP => TRUE); 8 END; &hellip; <a href=\"https:\/\/yangtingkun.net\/?p=650\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[531,532,425,533,86],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2yiY3-au","_links":{"self":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/650"}],"collection":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=650"}],"version-history":[{"count":1,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/650\/revisions"}],"predecessor-version":[{"id":651,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/650\/revisions\/651"}],"wp:attachment":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}