0

I need to check if the database connections are successful or not. Using command

sqlplus <username>/<password>@<SID>

If the connection is successful than the command returns a variable flagged as Y/N or whatever. This should be done for multiple servers and the flags stored in a file.

I am not sure how to conitnue?

Arcane
  • 151
  • 1
  • 11

1 Answers1

1

Linux Platform

TWO_TASK=TNS_ALIAS

sqlplus -s /nolog <<!
whenever sqlerror exit 1;
connect user/pass;
select * from dual;
exit
!

if [ $? = 0 ]; then
    echo "success"
else
    echo "failed"
fi

Windows Platform

set local=TNS_ALIAS
@(
   echo whenever sqlerror exit 1^; 
   echo connect user/pass;
   echo select * from dual^;
   echo exit^;
) > %TEMP%\run.sql
sqlplus /nolog @%TEMP%\run.sql

if "%errorlevel%"=="0" cls &echo success.
if "%errorlevel%"=="1" cls &echo failed
Bjarte Brandt
  • 4,191
  • 2
  • 23
  • 25