Monday, May 2, 2016

Check Database availability

In Automation process , you can use below script, check DB available or not.


#!/bin/ksh

. ~oracle/.bash_profile

if (( $# < 1 || $# > 1 ))
then
        print "Incorrect arguments"
        print "Usage : $0 <DATABASE_CONNECT_STRING>"
        exit
fi

DATABASE_NAME=$1
DBA_PWD=`cat ~oracle/.pwd`
LOG=/tmp/check_db.${DATABASE_NAME}.log

####################################################################################

$ORACLE_HOME/bin/sqlplus system/${DBA_PWD}@${DATABASE_NAME}  << EOF > ${LOG}
set pages 0
select 'Testing DB Connection' from dual;
exit;
EOF

if grep 'Testing DB Connection' ${LOG} ;
then
exit 0
else
mail -s '***ERROR: DB Connection Error for '"${DATABASE_NAME}"'@'"${MACHINE}"'. Please check.('"$0"')' $DBAEMAIL < ${LOG};
exit 1
fi