I'd like to know if its possible to get sqlplus
output in some way to discover if my database is up.
I want to run a list of scripts on a database, but before I do that, I want to know if the database is up and running with my script.
Here is what I tried:
sqlplus /@DB1 << EOF
> select 1 from dual;
> EOF
It cannot connect, but the return code of sqlplus still says "everything OK"!
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
I know I could grep the result of my test query, like that:
a.sh
sqlplus /@DB1 << EOF
select 'ALL_GOOD_BOY' from dual;
EOF
call:
gives 1
line if connection works, 0
otherwise:
$ a.sh |grep ALL_GOOD_BOY|wc -l
... This seems many steps to me. Any other way to set sqlplus in a mode where "unable to connect" gives an "error" return code?