Shell脚本Oracle模式刷新生成错误

时间:2014-04-24 17:50:17

标签: shell unix aix

我正在使用已经成功运行了很长时间的AIX Kornshell脚本,这会删除一个架构并从.dmp文件重新创建它。它最近在出错后开始挂起,似乎它没有使用正确的语法。我希望有人可以帮助我或指出我正确的方向。该脚本包含以下代码:

echo "Dropping user objects"
sqlplus $T_USERID/$T_PASSWD@$T_ORACLE_SID << SQL_START_STOP
set feedback off
set heading off
set termout off
set echo off
set pagesize 0
set linesize 100
spool /tmp/drop_objects.sql

select 'connect $T_USERID/$T_PASSWD@$T_ORACLE_SID' from dual;

select 'drop '||object_type||' '||object_name||' cascade constraints purge;'
from dba_objects
where object_type = 'TABLE'
  and owner = 'STSC';

select 'drop '||object_type||' '||object_name||' purge;'
from dba_objects
where object_type NOT IN ('TABLE', 'INDEX','TRIGGER')
  and owner = 'STSC'
order by object_type, object_name;

select 'connect $T_CSMUSERID/$T_CSMPASSWD@$T_ORACLE_SID' from dual;

select 'drop '||object_type||' '||object_name||' cascade constraints purge;'
from dba_objects
where object_type = 'TABLE'
  and owner = 'CSMMGR';

select 'drop '||object_type||' '||object_name||' purge;'
from dba_objects
where object_type NOT IN ('TABLE', 'INDEX','TRIGGER')
  and owner = 'CSMMGR'
order by object_type, object_name;

select 'commit;' from dual;
select 'exit;' from dual;

spool off

set feed on
set termout on
@/tmp/drop_objects.sql

SQL_START_STOP

脚本当前正在编写以下输出(我只捕获了相关位):

...Many more lines of dropped functions, procedures, etc. above
drop SEQUENCE VP_NOTEKEY_SEQ purge;
drop SEQUENCE VP_NOTE_SEQ purge;
drop SEQUENCE VP_TLIST_ITEM_SEQ purge;
drop SEQUENCE VP_TLIST_SEQ purge;
drop VIEW SRE_JOB_STATUS purge;
SQL> SQL> commit;
SQL> exit;
SQL> SQL> SQL> SQL> SQL> SQL> SP2-0042: unknown command "SQL>" - rest of line ignored.
SP2-0734: unknown command beginning "SQL> selec..." - rest of line ignored.
Connected.
SP2-0042: unknown command "SQL>" - rest of line ignored.
SP2-0734: unknown command beginning "SQL> selec..." - rest of line ignored.
drop TABLE DFU_jan13 cascade constraints purge

所以它似乎在以下几行之后出错了:

select 'commit;' from dual;
select 'exit;' from dual;

可能在这一特定行:

SQL_START_STOP

在我看来,语法已关闭,但我不确定,因为我很少编写shell脚本。

更新:在检查生成的SQL之后,我可以看到错误发生在哪里,但我无法确定为什么。

以下是生成的SQL文件中的错误行:

(在最顶端)

SQL> 
SQL> select 'connect stsc/stsc123@USTST641' from dual;
connect stsc/stsc123@USTST641                                                                       
SQL> 
SQL> select 'drop '||object_type||' '||object_name||' cascade constraints purge;'
  2  from dba_objects
  3  where object_type = 'TABLE'
  4    and owner = 'STSC';
drop TABLE DFU_jan13 cascade constraints purge;                                                     
SQL> 
SQL> select 'drop '||object_type||' '||object_name||' purge;'
  2  from dba_objects
  3  where object_type NOT IN ('TABLE', 'INDEX','TRIGGER')
  4    and owner = 'STSC'
  5  order by object_type, object_name;

(靠近底部)

SQL> 
SQL> select 'commit;' from dual;
commit;                                                                                             
SQL> select 'exit;' from dual;
exit;      

更新:我发现生成的SQL文件包含Windows End Of Line字符(CR LF)。我目前正在研究如何将SQL Plus设置为假脱机到UNIX行结尾字符(仅LF

0 个答案:

没有答案