概述
今天分享下怎么去监控Oracle数据库的告警日志文件,注意这里是采用Perl结合Shell的方式,因为Shell获取错误的时间、行数等不如Perl操作字符串方便。
以下基于Oracle 11.2.0.4 RAC ,操作系统为redhat 6.6进行测试。
1、脚本:monitoring_alert_log.pl
#********************************************************************************** # FileName :monitoring_alert_log.pl #********************************************************************************** # Author :hwb # CreateDate :2019-09-02 # Description :check the alert log and find out the ora error #*********************************************************************************** #! /usr/bin/perl use strict; my($argv) = @ARGV; if ( @ARGV != 1) { print ' Parameter error: you must assined the alert log file as a input parameter or the number of prarameter is not right. '; exit } if( ! -e $argv ) { print ' Usage: monitoring_alert_log.pl $ cat alert_[sid].log | monitoring_alert_log.pl $ tail -f alert_[sid].log | monitoring_alert_log.pl $ monitoring_alert_log.pl alert_[sid].log '; exit; } my $err_regex = '^(\w+ \w+ \d{2} \d{2}:\d{2}:\d{2} \d{4})|(ORA-\d+:.+)