检查 oracle db 模式,因为另一个用户失败了

问题描述 投票:0回答:1

我试图通过执行以下代码来获取 Oracle DB 模式 - 如果它处于读写模式 - 但出现错误。

我尝试过:

status=$(su - orasid -c "sqlplus "/as sysdba " \<\<EOF
select name,open_mode from v$database;
exit;
EOF")

echo $status

期望:

NAME  OPEN_MODE
-----------------------------
SMJ   READ WRITE

结果:

SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jan 22 10:08:57 2024 Version 19.16.0.0.0 Copyright (c) 1982, 2022, Oracle. All rights reserved. SQL*Plus: Release 19.0.0.0.0 - Production Version 19.16.0.0.0 Copyright (c) 1982, 2022, Oracle. All rights reserved. Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements. Usage 1: sqlplus -H | -V -H Displays the SQL*Plus version and the usage help. -V Displays the SQL*Plus version. Usage 2: sqlplus
...truncated
oracle sqlplus heredoc
1个回答
0
投票

您似乎想要更多类似的东西:

status=$(su - orasid -c "sqlplus -s -l / as sysdba" <<EOF
select name,open_mode from v\$database;
exit;
EOF
)

你有额外的双引号和转义符;但我们没有转义

$
中的
v$database
,并且结束
)
需要单独位于一行,这样就不会混淆定界文档处理。

我还添加了

-l
标志,这样如果第一次失败,它就不会尝试登录三次,并添加
-s
来抑制横幅。

根据您计划对结果执行的操作,您可能还想抑制列标题,并且可能只查询

open_mode
列。

© www.soinside.com 2019 - 2024. All rights reserved.