【问题标题】:for db recover process testing, unable obtain the query o/p using shell script对于db recovery进程测试,无法使用shell脚本获取查询o/p
【发布时间】:2018-03-24 17:13:06
【问题描述】:

我写的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查询的spool输出,如何解决?

【问题讨论】:

  • 更详细地描述您的问题。预期的输出是什么? “无法获得”是什么意思?你遇到了什么错误?
  • 第一部分,EOF 到 EOF 工作,但第二部分 EOF1,uanble 运行
  • 运行脚本时,RMAN 部分成功完成,但出现错误:./rmanrecover.sh: line 19: warning: here-document at line 13 delimited by end-of-file (wanted `_EOF1_') ,并且不运行 sqlplus 部分,但是虽然 rman 部分是用一个脚本编写的,而相同的 sqlplus 部分是用另一个脚本编写的,并从 rman 脚本调用 sqlplus 脚本,但成功运行。
  • 不要在 cmets 中发布澄清,而是编辑问题以包含该信息。

标签: oracle rman


【解决方案1】:

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

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

有两种方法可以实现您的目标。您将两者合二为一。有什么原因吗?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多