crontab对oracle操作问题处理

[root@localhost home]# vi test.sh
#!/bin/sh
ORACLE_HOME=/oracle/ora10/product
export ORACLE_HOME
userpwd=test/test@10.11.0.235:1521/ora10g
$ORACLE_HOME/bin/sqlplus -S $userpwd <alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
INSERT INTO test values(1,'test');
COMMIT;
EOF
exit;
 
以上test.sh文件中必须设置ORACLE_HOME环境变量,否则加入到crontab 里不能正常执行(如把环境变量注释掉:#ORACLE_HOME=/oracle/ora10/product
#export ORACLE_HOME
),即使在sqlplus前加绝对路径/oracle/ora10/product/bin也不行,crontab文件如下test1_crond ,日志见/var/log/cron

[root@localhost cron.d]# vi test1_crond
* * * * *  root sh /home/test.sh  >/home/test.log
~
~
SQL> conn test/test
Connected.
SQL> select * from test;
        ID NAME
---------- --------------------
         1 test
         1 test
         1 test
SQL>

[root@localhost cron.d]# tail -f /var/log/cron
Aug 17 14:03:01 localhost crond[10718]: (root) CMD (sh /home/x.sh)
Aug 17 14:03:01 localhost crond[10720]: (root) CMD (sh /home/test.sh  >/home/test.log)
Aug 17 14:04:01 localhost crond[11102]: (root) CMD (sh /home/x.sh)
Aug 17 14:04:01 localhost crond[11103]: (root) CMD (sh /home/test.sh  >/home/test.log)
Aug 17 14:05:01 localhost crond[11449]: (root) CMD (sh /home/x.sh)
Aug 17 14:05:01 localhost crond[11452]: (root) CMD (sh /home/test.sh  >/home/test.log)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16400082/viewspace-741269/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/16400082/viewspace-741269/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值