#--execute SQL to get some diagnostic variables
unset SQLPATH
unset ORACLE_PATH
DUMP_PATH=`sqlplus -S '/ as sysdba' << EOF
set pagesize 0 feedback off verify off heading off echo off
SELECT value FROM v\\$diag_info where name='Diag Trace';
exit
EOF`
echo "The background_dump_dest value: ${DUMP_PATH}"
if [ ! -d ${DUMP_PATH} ]; then
echo "The bdump directory was not found for ${ORACLE_SID}"
exit 95
fi
# alert trace file name
ALERT_FNAME=alert_${ORACLE_SID}.log
# alert trace file full name
ALERT_CUR="${DUMP_PATH}/${ALERT_FNAME}"
if [ ! -f ${ALERT_CUR} ]; then
echo "The alert log was not found for ${ORACLE_SID}"
exit 94
else
echo "The alert log filename : ${ALERT_FNAME}"
fi
ALERT_BAK="${ALERT_CUR}_last"
# alert trace file size
FILESIZE=`ls -l ${ALERT_CUR}|awk '{ printf "%.0f", $5/1024/1024 }'`
echo "The alert log current filesize(MB):${FILESIZE}"
if [ ${FILESIZE} -gt ${FILESIZELIMIT} ]
then
echo "The alert log is bigger than ${FILESIZELIMIT} MB"
echo "The alert log will be backup to ${ALERT_BAK}"
# cut alert log file
echo "mv -f ${ALERT_CUR} ${ALERT_BAK}"
mv -f ${ALERT_CUR} ${ALERT_BAK}
# to generate a new alert
$ORACLE_HOME/bin/sqlplus -S "/ as sysdba" <<EOF
set pagesize 0 feedback off verify off heading off echo off
exec dbms_system.ksdwrt(2, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
exec dbms_system.ksdwrt(2, 'the alert had archived by alert log clear shell!');
exec dbms_system.ksdfls;
exit
EOF
# to compress alchived alert log file
echo "gzip -f ${ALERT_BAK}"
gzip -f ${ALERT_BAK}
else
echo "The alert log is litter than ${FILESIZELIMIT} MB"
fi
评论