sqlplus -S username/password@sid << _END select * from dual; exit; _END RC=$? if [ $RC -eq 0 ]; then echo "Database connection OK" else echo "Unable to reach database" fi
If you need to connect to another machine, then you need to change the sqlplus connect string to e.g. sqlplus -s "sys/password@servicename as sysdba". For this to work you need to have a password file on the remote computer and REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE. Please be aware that anybody listing process on your host computer can see the connect string including the password while the procedure is running.
ORACLE_SID=my_instance_name ORACLE_HOME=/my_path_to_oracle_home_directory LD_LIBRARY_PATH=$ORACLE_HOME/lib PATH=$ORACLE_HOME/bin:$PATH export PATH export ORACLE_HOME export ORACLE_SID export LD_LIBRARY_PATH ora_status=`echo 'set heading off select status from v$instance; exit' | sqlplus -s / as sysdba` if [ $ora_status = "OPEN" ]; then echo "Database is up and running..." fi