Oracle脚本(二)
公司数据库比较多,所以需要做个定时任务,每隔15分钟检查一次alert.log的内容,如果有错误就发到邮箱,方便管理。以下是我参考网络文档,修改后在工作中使用到的脚本。数据库11.2.0,操作系统Centos6.3.[*]$ cat ./test.sh
[*]#!/bin/bash
[*]ORACLE_SID=orcl; export $1
[*]ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
[*]ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1; export ORACLE_HOME
[*]export ORACLE_SID=$1
[*]$ORACLE_HOME/bin:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/sbin:/usr/openwin/bin:/opt/bin:.; export PATH
[*]export ALERT_DIR=/u01/app/oracle/diag/
[*]export ORACLE_SID=orcl
[*]export MACHINE=`hostname`
[*]DBALIST="masicong1019@hotmail.com";export DBALIST
[*]db_stat=`ps -ef | grep pmon_$ORACLE_SID | grep -v grep| cut -f3 -d_`
[*]if [ -z "$db_stat" ]; then
[*] date >/tmp/db_${ORACLE_SID}_stauts.log
[*] echo " $ORACLE_SID is not available on ${MACHINE} !!!" >>/tmp/db_${ORACLE_SID}_stauts.log
[*] MAIL_SUB=" $ORACLE_SID is not available on ${MACHINE} !!!"
[*] $MAIL_DIR/sendEmail -u $MAIL_SUB -f $MAIL_FM -t $MAIL_LIST -o message-file=/tmp/db_${ORACLE_SID}_stauts.log
[*] exit 1
[*]fi;
[*]sqlplus'/ as sysdba' /dev/null
[*]DT=`date +%Y%m%d`
[*]DT_DIR=`date +%Y%m`
[*]ARCH_DIR=${ALERT_DIR}/${DT_DIR}
[*]echo 'a'
[*]if [ ! -d "${ARCH_DIR}" ] ; then
[*] mkdir $ARCH_DIR
[*]fi
[*]ORIG_ALERT_LOG=${ALERT_DIR}/alert_${ORACLE_SID}.log
[*]NEW_ALERT_LOG=${ARCH_DIR}/alert_${ORACLE_SID}.log.${DT}
[*]TEMP_ALERT_LOG=${ORIG_ALERT_LOG}.temp
[*]AWK_DIR=/home/oracle
[*]
[*]cat ${ORIG_ALERT_LOG} | awk -f $AWK_DIR/check_alert.awk > /tmp/${ORACLE_SID}_check_monitor_log.log
[*]if [ -s "/tmp/${ORACLE_SID}_check_monitor_log.log" ];
[*] then
[*]$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 }
[*] cat /tmp/${ORACLE_SID}_check_monitor_log.log >>/tmp/${ORACLE_SID}_check_monitor_log.mail
[*] MAIL_SUB="Found errors in ${ORACLE_SID} on ${MACHINE}"
[*] $MAIL_DIR/sendEmail -u $MAIL_SUB -f $MAIL_FM -t $MAIL_LIST -o message-file=/tmp/${ORACLE_SID}_check_monitor_log.mail
[*]
页:
[1]