我想知道是否有可能以某种方式获取sqlplus输出以发现我的数据库是否已启动.
我想在数据库上运行一个脚本列表,但在此之前,我想知道数据库是否已启动并运行我的脚本.
这是我尝试过的:
- sqlplus /@DB1 << EOF
- > select 1 from dual;
- > EOF
它无法连接,但sqlplus的返回码仍然说“一切正常”!
- sql*Plus: Release 11.2.0.4.0 Production on Mon Nov 28 10:06:41 2016
- Copyright (c) 1982,2013,Oracle. All rights reserved.
- ERROR:
- ORA-12505: TNS:listener does not currently know of SID given in connect
- descriptor
- Enter user-name: SP2-0306: Invalid option.
- Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
- where ::= [/][@]
- ::= [][/][@]
- Enter user-name: ju@srv:/tmp/jcho $echo $?
- 0
我知道我可以grep我的测试查询的结果,像这样:
灰
- sqlplus /@DB1 << EOF
- select 'ALL_GOOD_BOY' from dual;
- EOF
呼叫:
如果连接有效,则给出1行,否则为0:
- $a.sh |grep ALL_GOOD_BOY|wc -l