test.sh脚本如下:
#!/bin/sh
sqlplus /nolog<<ENDOFINPUT
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 --
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com