对于db recover process testing,无法使用shell脚本获取查询o / p

时间:2017-10-12 16:59:46

标签: oracle rman

我编写了shell脚本:

#!/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查询中获取假脱机的输出,如何解决问题?

1 个答案:

答案 0 :(得分:0)

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

layout:table

<强>输出

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

输出2

$ 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

有两种方法可以实现您的目标。你们两个都使用。有什么原因吗?

选项1

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

D                                                                               
-                                                                               
X                                                                               

SQL>         spool off;

输出

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

选项2

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

D                                                                               
-                                                                               
X                                                                               

SQL> spool off

输出

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