我的实行sqlplus的Shell脚本有什么问题?

zhoulx 2003-08-21 07:18:00
我需要在UNIX下让ORACLE定时执行*.sql文件,做成了如下脚本test.sh

#!/sbin/sh

ORACLE_BASE=/usr2/oracle;export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/app/oracle/product/9.0.1;export ORACLE_HOME

PATH=$ORACLE_HOME/bin:/usr/ccs/bin:/usr/bin:/etc:/usr/openwin/bin:/usr/local/bin:/$ORACLE_HOME/batch;export PATH
ORACLE_SID=necwl;export ORACLE_SID
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data;export ORA_NLS33
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;export NLS_LANG

su -l oracle -c "sqlplus necwl/necwl@necwl"</dev/null
spool tables.txt;
@test.sql;
spool off;
exit;

其中test.SQL文件的内容如下
select * from sql;

在命令行实行sh test.sh时,系统提示如下错误信息
$ sh test.sh
Password:
Sun Microsystems Inc. SunOS 5.6 Generic August 1997
mail: Invalid permissions on /var/mail/oracle

SQL*Plus: Release 9.0.1.0.0 - Production on Thu Aug 21 18:56:23 2003

(c) Copyright 2001 Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.0.1.0.0 - Production
With the Partitioning option
JServer Release 9.0.1.0.0 - Production

SQL> Disconnected from Oracle9i Enterprise Edition Release 9.0.1.0.0 - Production
With the Partitioning option
JServer Release 9.0.1.0.0 - Production
test.sh: spool: not found
test.sh: @test.sql: not found
test.sh: spool: not found

请帮忙看看是什么问题,谢谢了。
...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Aglaia 2003-08-27
  • 打赏
  • 举报
回复
use su -l oracle -c "sqlplus necwl/necwl @test.sql"</dev/null

for execute the external .sql file
yiyi999999999 2003-08-23
  • 打赏
  • 举报
回复
用绝对路径试试看
在java代码中调用执行shell脚本,sqlldr导数与使用sqlplusshell调用执行存储过程。 linux环境中有2个dba的用户:oracle、erm 还有1个web用户:erm 在linux环境中,这三个用户都可以直接在任意目录下执行该shell脚本,可是在java代码中调用shell脚本时,报了如下4个错误: 1、sqlldr: command not found 2、sqlplus: command not found 3、0750: You may need to set ORACLE_HOME to your Oracle software directory 4、Message 2100 not found; No message file for product=RDBMS, facility=ULMessage 2100 not found; No message file for product=RDBMS, facility=UL$ 检查了dba用户和web用户下关于oracle的所有环境变量发现没有问题 (/home/oracle/.profile 与 /home/erm/.profile 环境变量文件为隐藏文件需使用 ls -a 命令查看) 在网上查了一遍以后有如下几种处理办法: 1、没有oracle_home目录的执行权限,无法进入到bin目录,使用chmod 755 $oracle_home更改目录权限;使用chmod 755 $oracle_home/lib更改目录权限;对目录$oracle_home/rdbms/mesg目录赋予相应权限;当需要给非oracle用户配置使用sqlldr时,不单需要配置环境变量,还需要把相关目录的访问权限赋予该用户。【采用此法测试以后还是出现上面的错误】 2、用sh直接执行shell和在java直接执行shell是有区别的,要在shell文件内增加oracle的环境变量即. /home/oracle/.bash_profile 这句话,否则在执行sqlldr会报如下异常: Message 2100 not found; No message file for product=RDBMS...... facility=UL 【采用此法测试以后继续报错,但是这个方法有引导作用,继续往下看】 因为我在linux环境下执行shell脚本时sqlldr命令和sqlplus命令是正常执行的,没有任何问题,但是在java代码中调用脚本时却报错,所有排除了其他原因,只可能是环境变量的问题, 于是我把oracle的所有环境变量直接复制到shell脚本文件中,在java中调用了一下,然后所有问题迎刃而解! 具体代码参看文件内容

23,115

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧