#!/bin/ksh
#script : Rick Stehno
# script will monitor to see if Oracle is up
while [ "$1" != "" ]
do
ORACLE_INSTANCE=$1
ORACLE_TNS=$2
USR_ID=sys
USR_PASS=$3
# echo "Instance: [$ORACLE_INSTANCE]"
# echo "TNS [$ORACLE_TNS]"
# echo "PASS: [$USR_PASS]"
LOGFIL=/u01/app/oracle/admin/monitordev1.out
NOTIFY_LIST=userid1@mobilephone.com,userid2,userid3@pagercompany.com
#
# 检测关键的段没有达到最大限度
sqlplus -s <$LOGFIL 2>/dev/null
$USR_ID/$USR_PASS@$ORACLE_TNS
set pages 0
select distinct 'YES' from dba_segments
where extents >= (max_extents-5) and segment_name not like '1.%';
EOF1
grep -i '^ORA-' $LOGFIL >/dev/null
if [ $? -eq 0 ]
then
echo "$0 failed: check $ORACLE_INSTANCE for problems" | /bin/mailx -
s "${ORACLE_INSTANCE} : Script failed" $NOTIFY_LIST
exit 1
fi
MAXEXTENTS_REACHED=`awk '{ print $1 }' $LOGFIL`
if [ "$MAXEXTENTS_REACHED" = "YES" ]
then
echo "$0 failed: $ORACLE_INSTANCE max extents reached" | /bin/mailx -
s "${ORACLE_INSTANCE} : max extents reached" $NOTIFY_LIST
exit 1
fi
#
# 检测是否能分配下一个段
sqlplus -s <$LOGFIL 2>/dev/null
$USR_ID/$USR_PASS@$ORACLE_TNS
set pages 0
select distinct 'YES' from dba_segments ds
where next_extent >
(select max(bytes) from dba_free_space
where tablespace_name = ds.tablespace_name);
EOF2
grep -i '^ORA-' $LOGFIL >/dev/null
if [ $? -eq 0 ]
then
echo "$0 failed: check $ORACLE_INSTANCE for problems" | /bin/mailx -
s "${ORACLE_INSTANCE} : Script failed" $NOTIFY_LIST
exit 1
fi
POSSIBLE_NEXTEXT_FAIL=`awk '{print $1 }' $LOGFIL`
if [ "$POSSIBLE_NEXTEXT_FAIL" = "YES" ]
then
echo "$0 failed: $ORACLE_INSTANCE cannot extend segment" | /bin/mailx -
s "${ORACLE_INSTANCE} : max extents reached" $NOTIFY_LIST
exit 1
fi
shift 3
# echo "shift done"
done
echo "Successful completion of $0" `date`
exit 0