2017-10-12 29 views
0

我已经写壳脚本无法获得查询O/P为:为分贝恢复过程的测试,使用外壳脚本

#!/bin/bash 
#shell script for recovery testing 
$ORACLE_HOME/bin/rman target/ <<EOF >rman.log 
     shutdown immediate; 
     startup mount; 
     run 
     { 
       recover database; 
     } 
     sql 'alter database open read only'; 
exit; 
EOF 

$ORACLE_HOME/bin/sqlplus '/as sysdba' <<_EOF1_ >sql.log 
     spool '/home/oracle/test1.log' 
     select * from hr.employees; 
     spool off; 
exit; 
_EOF1_ 

,但无法获得线轴从SQL查询,如何解决输出问题?

+0

更详细地描述你的问题。预期产出是多少?这是什么意思“无法获得”?你遇到什么错误? – tambre

+0

第一部分,EOF到EOF工作,但第二部分_EOF1_,运行脚本时可运行 –

+0

,RMAN部分已成功完成,出现错误:./rmanrecover.sh:第19行:警告:此处 - 第13行的文档在第13行(想要'_EOF1_'),并且不运行sqlplus部分,但是当rman部分被写入一个脚本中,并且相同的sqlplus部分被写入其他脚本并且从rman脚本调用sqlplus脚本成功地工作。 –

回答

0

我不知道你的代码有什么问题。它应该工作。我测试了它:

$ sqlplus '/as sysdba' <<_EOF1_ >sql.log 
     spool '/home/oracle/test1.log' 
     select * from dual; 
     spool off; 
exit; 
_EOF1_ 

输出

$ cat sql.log 

SQL*Plus: Release 11.2.0.4.0 Production on Mon Nov 6 15:18:42 2017 

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


Connected to: 
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, 
Data Mining and Real Application Testing options 

SQL> SQL> 
D 
- 
X 

SQL> SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, 
Data Mining and Real Application Testing options 

输出2

$ cat /home/oracle/test1.log 
SQL>   select * from dual; 

D                    
-                    
X                    

SQL>   spool off; 

有两种选择acomplish你的目标。你在一个使用两个。有什么理由呢?

选项1

$ sqlplus/as sysdba <<EOF> /dev/null 
spool test.out 
select * from dual; 
spool off 
EOF 

输出

$ cat test.out 
SQL> select * from dual; 

D                    
-                    
X                    

SQL> spool off 

选项2

$ sqlplus/as sysdba <<EOF> test.out 
> select * from dual; 
> EOF 

输出

$ cat test.out 

SQL*Plus: Release 11.2.0.4.0 Production on Mon Nov 6 15:12:05 2017 

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


Connected to: 
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, 
Data Mining and Real Application Testing options 

SQL> 
D 
- 
X 

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, 
Data Mining and Real Application Testing options