手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下配置DB2定时任务

[日期:2012-09-26] 来源:Linux社区  作者:jacki6 [字体:大 中 小]

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  

存盘退出即可。

linux
相关资讯       DB2 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款