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

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

Jun 07, 2016 pm 05:26 PM
linux shell monitor

使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以

使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,,以及数据库的备份,AWR report的自动邮件等。本文给出Linux 下使用 shell 脚本来监控 Oracle 告警日志(monitor alter log file)。

Linux Shell的相关参考:

Linux/Unix shell 脚本中调用SQL,RMAN脚本

Linux/Unix shell sql 之间传递变量

Linux Unix shell 调用 PL/SQL

1、监控Oracle告警日志脚本

robin@SZDB:~/dba_scripts/custom/bin> more ck_alert.sh
#!/bin/bash
# --------------------------------------------------------------------------+
#                  CHECK ALERT LOG FILE                                    |
#  Filename: ck_alert.sh                                                  |
#  Desc:                                                                  |
#      The script use to check alert log file.                            |
#      Once any error was caught, a mail alert will be sent.              | 
#      Deploy it by crontab. e.g. per 15 min                              | 
#  Usage:                                                                  |
#      ./ck_alert.sh $ORACLE_SID                                          | 
#                                                                          |
#  Author : Robinson                                                      |
#  Blog  : 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 ORACLE_SID=$1
export MACHINE=`hostname`
export MAIL_DIR=/users/robin/dba_scripts/sendEmail-v1.56
export MAIL_LIST='Robinson.chen@12306.com'
export MAIL_FM='oracle@szdb.com'

# ----------------------------------------------
# check 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
    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;

# --------------------------------------
#  Get the location of alert log file
# --------------------------------------

sqlplus '/ as sysdba' /tmp/${ORACLE_SID}_monitor_temp.txt
column xxxx format a10
column value format a80
set lines 132
SELECT 'xxxx' ,value FROM  v\$parameter WHERE  name = 'background_dump_dest'
/
exit
EOF

cat /tmp/${ORACLE_SID}_monitor_temp.txt | awk '$1 ~ /xxxx/ {print $2}' > /tmp/${ORACLE_SID}_monitor_location.txt
read ALERT_DIR rm /tmp/${ORACLE_SID}_monitor_temp.txt 2>/dev/null

# ----------------------------------------
#  Define archive directory and log file
# ----------------------------------------

DT=`date +%Y%m%d`
DT_DIR=`date +%Y%m`
ARCH_DIR=${ALERT_DIR}/${DT_DIR}

if [ ! -d "${ARCH_DIR}" ] ; then
    mkdir $ARCH_DIR
fi

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Affordable Xiaomi Gaming Monitor G24i makes global debut with 180 Hz display and AMD FreeSync Affordable Xiaomi Gaming Monitor G24i makes global debut with 180 Hz display and AMD FreeSync Sep 11, 2024 am 06:39 AM

The Xiaomi Gaming Monitor G24i has made its global debut, and it's the most affordable option in the new lineup. It has an FHD IPS screen that the company claims is ideal for competitive gamers. The 23.8-inch panel has a 180 Hz refresh rate and 1 ms

109 practical shell script examples, the code is clear and easy to use! 109 practical shell script examples, the code is clear and easy to use! Aug 02, 2023 pm 03:25 PM

Shell scripts use the command interpretation function of Shell to parse a plain text file and then execute these functions. It can also be said that a Shell script is a collection of a series of commands.

Linux Shell Scripting Security: Avoiding Security Vulnerabilities Linux Shell Scripting Security: Avoiding Security Vulnerabilities Sep 09, 2023 pm 05:15 PM

Security of Linux Shell Scripting: Avoiding Security Vulnerabilities Introduction: With the popularity and application of Linux operating system, Linux shell script programming has become a very important skill. However, due to the nature and usage of shell scripts, writing unsafe scripts may lead to security vulnerabilities. This article explores how to write secure shell scripts and uses code examples to illustrate how to avoid common security vulnerabilities. 1. Avoid using clear text passwords in shell scripts to avoid

IFA 2024 | Nitro GS272U M debuts as Acer\'s latest take on the smart gaming monitor IFA 2024 | Nitro GS272U M debuts as Acer\'s latest take on the smart gaming monitor Sep 05, 2024 am 06:41 AM

The NitroGS272U M has joined theAcer CS322Qin being introduced as a smart monitor atIFA 2024- however, theformer has the more gamer-like stand of itsGA-seriespredecessors. It also has a smaller 27-inch display - although the glare-free WQHD IPS panel

MSI: After user criticism, cheaper gaming OLEDs will also receive firmware updates - only after a potentially costly update MSI: After user criticism, cheaper gaming OLEDs will also receive firmware updates - only after a potentially costly update Jun 27, 2024 pm 10:03 PM

Monitors can now often be used with extensive setting options and come with their own firmware. A corresponding user interface can be updated as part of firmware updates, for example, and in principle new functions can also be implemented - or bugs c

Alienware unveils unique 27” gaming monitor AW2725QF with dual resolution and refresh-rate modes Alienware unveils unique 27” gaming monitor AW2725QF with dual resolution and refresh-rate modes Aug 17, 2024 am 06:52 AM

Dell has just unveiled a new 27-inch IPS gaming monitor with a special and rather useful trick up its sleeve that should appeal to enthusiasts and professional gamers. With the press of a button, the Alienware AW2725QF can switch between two combinat

Deal | Samsung 32-inch 240 Hz 4K Odyssey Neo G8 gaming monitor gets massive 43% discount in Amazon deal Deal | Samsung 32-inch 240 Hz 4K Odyssey Neo G8 gaming monitor gets massive 43% discount in Amazon deal Aug 07, 2024 pm 08:52 PM

Samsung's Odyssey gaming monitor line-up features some of the best gaming monitors money can buy, often delivering on top-tier features and specifications along with their flagship pricing. The Odyssey Neo G8 sits at the higher end of Samsung's Odyss

109 practical shell script examples, the code is clear and easy to use! 109 practical shell script examples, the code is clear and easy to use! Aug 01, 2023 pm 05:43 PM

Shell scripts use the command interpretation function of Shell to parse a plain text file and then execute these functions. It can also be said that a Shell script is a collection of a series of commands.

See all articles