title: How to verify sqlplus can connect?
body: <p>I'd like to know if its possible to get <code>sqlplus</code> output in some way to discover if my database is up.</p>
  <p>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.</p>
  <p>Here is what I tried:</p>
  <pre><code> sqlplus /@DB1 &lt;&lt; EOF
   &gt; select 1 from dual;
   &gt; EOF
  </code></pre>
  <p>It cannot connect, but the return code of sqlplus still says &quot;everything OK&quot;!</p>
  <pre>
  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
  </pre>
  <p>I know I could grep the result of my test query, like that:</p>
  <h1>a.sh</h1>
  <pre><code>sqlplus /@DB1 &lt;&lt; EOF
    select 'ALL_GOOD_BOY' from dual;
  EOF
  </code></pre>
  <h1>call:</h1>
  <p>gives <code>1</code> line if connection works, <code>0</code>  otherwise:</p>
  <pre><code>$ a.sh |grep ALL_GOOD_BOY|wc -l
  </code></pre>
  <p>... This seems many steps to me. Any other way to set sqlplus in a mode where &quot;unable to connect&quot; gives an &quot;error&quot; return code?</p>