Chinaunix首页 | 论坛 | 博客
  • 博客访问: 63194
  • 博文数量: 24
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-24 11:49
文章分类

全部博文(24)

文章存档

2015年(15)

2014年(7)

2013年(2)

我的朋友

分类: LINUX

2014-03-10 13:52:44

原文地址:该死的crontab环境变量问题 作者:hxl


test.sh脚本如下:
#!/bin/sh
sqlplus /nolog<
    whenever sqlerror exit 20;
    whenever oserror exit 20;
    connect hxl/hxl;
    variable cnt number;
    begin
    select Count(1) into :cnt from dual;
    if :cnt = 0 then
     :cnt:=0;
    else
     :cnt:=99;
    end if;
    end;
/
exit :cnt
ENDOFINPUT
flag=$?
echo $flag


手工执行没有问题
[etl@node1 shell]$ ./test.sh


SQL*Plus: Release 11.2.0.3.0 Production on Fri Mar 7 11:29:19 2014


Copyright (c) 1982, 2011, Oracle.  All rights reserved.


SQL> SQL> SQL> Connected.
SQL> SQL>   2    3    4    5    6    7    8    9  
PL/SQL procedure successfully completed.


SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
99
[etl@node1 shell]$ 


crontab内容如下:
[etl@node1 log]$ crontab -l
20 11 * * * /home/etl/shell/test.sh >>$HOME/log/output_test.log 2>&1






crontab中执行死活不了
[etl@node1 log]$ more output_test.log 
/home/etl/shell/test.sh: line 2: sqlplus: command not found
127




怀疑是环境变量问题,将如下两句添加到脚本中,问题解决.
. /etc/profile
. ~/.bash_profile

-- The End --

阅读(896) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~