Friday, May 8, 2009

Database Monitor Script



MAILLIST="test@gmail.com"

if [ "$1" ]
then DBNAME=$1
else echo "\nOracle SID has not been entered."
exit 16
fi

sqlplus -silent <<> /tmp/$$.1 &
a/a@${DBNAME}
exit;
EOF

Pid=$!
sleep 2

if [[ `ps -ef grep -w "$Pid"` != "" ]] ; then
kill -9 $Pid
fi

egrep 'ORA-121ORA-01034' /tmp/$$.1 > /dev/null
if [[ $? = 0 ]]
then
echo " ${DBNAME} is not accessible - db is down"
mailx -s " ${DBNAME} is not accessible - db is down" ${MAILLIST} < /tmp/$$.1 else grep -e 'ORA-01017' -e 'ORA-01033' /tmp/$$.1 > /dev/null
if [[ $? = 0 ]]
then
echo " ${DBNAME} is accessible - db is up and running"
exit 16
else
echo " ${DBNAME} is not accessible - db is down"
mailx -s " ${DBNAME} is not accessible - db is down" ${MAILLIST} < /tmp/$$.1 fi fi rm /tmp/$$.1 exit

SQLPLUS edit and format tips


set long 500 longchunksize 500

list - print all rows
change - c /old/new
del - del 4 will delete 4th line
input - input order by 2 will append line as last line
APPEND - Adds specified text to the end of the current line in the buffer
#############Col and Report format################
ttitle - center 'Redo Log Summary' skip 2
col group# format 999 heading 'Group'
col member format a45 heading 'Member' justify c
col status format a10 heading 'Status' justify c
col archived format a10 heading 'Archived'
col fsize format 99 heading 'Size(MB)'