Oracl自动保存当天的alert日志文件到当月的目录下,方便日志的查看和归类。参考网上文章,修改了自己的一份脚本。
- #!/bin/bash
- ORACLE_SID=orcl; export ORACLE_SID
- ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1; export ORACLE_HOME
- DBALIST="masicong1019@hotmail.com";export DBALIST
- export MAIL_DIR=/usr/local/bin
- export MAIL_LIST='masicong1019@outlook.com'
- export MAIL_FM='masicong1019@outlook.com'
- ORACLE_SID=orcl; export ORACLE_SID
- db_stat=`ps -ef | grep pmon_$ORACLE_SID | grep -v grep| cut -f3 -d_`
- if [ -z "$db_stat" ]; then
- echo " $ORACLE_SID is not available on `hostname` !!!"
- MAIL_SUB=" $ORACLE_SID is not available on `hostname` !!!"
- MAIL_MSG="$ORACLE_SID is not available on `hostname` before age alert log file, exit,
- please check !"
- $MAIL_DIR/sendEmail -u $MAIL_SUB -f $MAIL_FM -t $MAIL_LIST -m $MAIL_MSG
- exit 1
- fi
- DUMP_DIR=`sqlplus -S '/ as sysdba' << EOF
- set pagesize 0 feedback off verify off heading off echo off
- SELECT value FROM v\\$parameter WHERE name = 'background_dump_dest';
- exit
- EOF
- if [ -z ${DUMP_DIR} ]; then
- echo "The bdump directory was not found for ${ORACLE_SID}"
- MAIL_SUB="The bdump directory was not found for ${ORACLE_SID}"
- MAIL_MSG="The bdump directory was not found for ${ORACLE_SID} on `hostname` before
- age log file,exit,please check !"
- $MAIL_DIR/sendEmail -u $MAIL_SUB -f $MAIL_FM -t $MAIL_LIST -m $MAIL_MSG
- exit 1
- else
- echo ${DUMP_DIR}
- fi
- DT=`date +%Y%m%d -d '-1 day'`
- OLD_DIR=${DT:0:6}
- NEW_DIR=`date +%Y%m`
- ORIG_ALERT_LOG=${DUMP_DIR}/alert_${ORACLE_SID}.log
- OLD_ARC_DIR=${DUMP_DIR}/${OLD_DIR}
- NEW_ARC_DIR=${DUMP_DIR}/${NEW_DIR}
- if [ ! -d "${NEW_ARC_DIR}" ] ; then
- mkdir ${NEW_ARC_DIR}
- fi
- if [ "${OLD_DIR}" \< "${NEW_DIR}" ];then
- ARC_LOG=${OLD_ARC_DIR}/alert_${ORACLE_SID}.log.${DT}
- else
- ARC_LOG=${NEW_ARC_DIR}/alert_${ORACLE_SID}.log.${DT}
- fi
- cat ${ORIG_ALERT_LOG} >>${ARC_LOG}
- cat /dev/null>${ORIG_ALERT_LOG}
- exit
本文出自 “无双城” 博客,请务必保留此出处http://929044991.blog.51cto.com/1758347/1179903