Jul 7, 2011

Check the DB connection through unix

Shell Script

#!/usr/bin/ksh

## Assign the User, Password and database name below
. `dirname $0`/$1
echo ". `dirname $0`/$1"
uname=$user_id
passwd=$pass
sid=$sid_nm

$ORACLE_HOME/bin/sqlplus $uname/$passwd@$sid << END
select user from dual;
exit
END

estatus=$?

if [ $estatus != 0 ]
then
    echo "Hi\n This is Just a test mail.\n Thanks,\nSupport Team" | mailx -s "Unable to connect to database $sid" ajit@XXX.com
fi

Config file:
export user_id=XXXX
export pass=XXXX
export sid_nm=DB_NAME(SID)

while run in unix u have to run both the shell and config file like below:
Script.sh  file.cfg
Note: This is for Oracle DB

No comments:

Post a Comment