手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux/Unix shell 监控Oracle告警日志(monitor alter log file)

[日期:2013-02-05] 来源:CSDN  作者:robinson [字体:大 中 小]

2、过滤Oracle告警日志错误信息

robin@SZDB:~/dba_scripts/custom/bin> more check_alert.awk
$0 ~ /Errors in file/ {print $0}
$0 ~ /PMON: terminating instance due to error 600/ {print $0}
$0 ~ /Started recovery/{print $0}
$0 ~ /Archival required/{print $0}
$0 ~ /Instance terminated/ {print $0}
$0 ~ /Checkpoint not complete/ {print $0}
$1 ~ /ORA-/ { print $0; flag=1 }
$0 !~ /ORA-/ {if (flag==1){print $0; flag=0;print " "} }
$0 ~ /ERROR_AUDIT/ {print $0}

3、老化Oracle告警日志脚本

robin@SZDB:~/dba_scripts/custom/bin> more age_alert.sh
#!/bin/bash
# ------------------------------------------------------------+
#                Age the alert log file                      |
#  FileName: age_alert.sh                                    |
#  Desc:                                                    |
#        The script use to age the alert log file            |
#  Usage:                                                    |
#        ./age_alert.sh $ORACLE_SID                          |
#                                                            |
#  Authror : Robinson                                        |
#  Blog    : http://blog.csdn.net/robinson_0612              |
# ------------------------------------------------------------+

# --------------------------
#  Check SID
# --------------------------

if [ -z "${1}" ];then
    echo "Usage: "
    echo "      `basename $0` ORACLE_SID"
    exit 1
fi

# -------------------------------
#  Set environment here
# ------------------------------

if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile
fi

export MAIL_DIR=/users/robin/dba_scripts/sendEmail-v1.56
export MAIL_LIST='Robinson.chen@2GoTrade.com'
export MAIL_FM='oracle@szdb.com'
ORACLE_SID=$1;  export ORACLE_SID

# ----------------------------------------------
# check if the database is running, if not exit
# ----------------------------------------------

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

# -----------------------------------
# Find bdump directory for database
# -----------------------------------

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

# -------------------------------
#  Archive alert log file
# -------------------------------

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

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款