Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6542575
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: LINUX

2014-03-07 14:07:31


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 --

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