Linux下配置DB2定時任務

來源:互聯網
上載者:User

1. 編寫sql指令碼

編寫DB2需要執行的sql執行指令碼,並存放到AIX伺服器上。

樣本如下crontest.sql:

  1. connect to tem user db2admin using db2admin;   
  2. call P_TEST();  

2. 編寫sh執行檔案

編寫sh檔案,並存放到AIX伺服器上,並修改sh檔案為可執。

樣本如下crontest.sh:

  1. PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.   
  2. export PATH   
  3. if [ -s "$MAIL" ]    # This is at Shell startup. In normal   
  4. then echo "$MAILMSG"    # operation, the Shell checks   
  5. fi    # periodically.   
  6. # The following three lines have been added by UDB DB2.   
  7. if [ -f /home/db2admin/das/dasprofile ]; then   
  8.     ./home/db2admin/das/dasprofile   
  9. fi   
  10. # The following three lines have been added by UDB DB2.   
  11. if [ -f /home/db2admin/sqllib/db2profile ]; then   
  12.     ./home/db2admin/sqllib/db2profile   
  13. fi   
  14.   
  15. #execute sql script   
  16. db2 -svtf /home/db2admin/task/crontest.sql -z /home/db2admin/task/crontest.log  

註:sh檔案的第一部分為設定db2執行需要的環境變數(必須設定),可以根據具體的實際情況進行修改,或直接將db2admin的.profile檔案中的變數直接複製過來。

  1. #修改sh檔案的屬性   
  2. chmod 777 crontest.sh  

3. 配置crontab

用db2admin使用者登陸AIX系統,使用crontab –e命令進行定時任務設定。crontab的具體命令參見附註中的說明。

樣本如下:

  1. # 設定每天02:00分定時執行crontest.sh指令碼   
  2. 00 02 * * * /home/db2admin/task/crontest.sh  

存檔退出即可。

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.