使用shell处理oracle数据库alert日志

上传人:wm****3 文档编号:41787966 上传时间:2018-05-31 格式:DOC 页数:8 大小:55KB
返回 下载 相关 举报
使用shell处理oracle数据库alert日志_第1页
第1页 / 共8页
使用shell处理oracle数据库alert日志_第2页
第2页 / 共8页
使用shell处理oracle数据库alert日志_第3页
第3页 / 共8页
使用shell处理oracle数据库alert日志_第4页
第4页 / 共8页
使用shell处理oracle数据库alert日志_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《使用shell处理oracle数据库alert日志》由会员分享,可在线阅读,更多相关《使用shell处理oracle数据库alert日志(8页珍藏版)》请在金锄头文库上搜索。

1、 本文给出使用 shell 实现对 oracle 数据库的 alert 日志进行处理的算法和 实现过程,并给出一个样例,实例表明,脚本能快速有效的分析 alert 日志, 满足需求,最后对处理过程进行展望。1.1. 背景概述背景概述对于日常的一些重复性的操作,以及在用户现场进行问题处理的过程中, 采用一些自动化的脚本,来完成一些工作,会使一些枯燥的工作变得简单、快 速,同时也不 容易出错。在为某些省份联通公司和财政厅实施服务的过程中, 了解到用户有如下的需求:提供 shell 脚本,实现对 oracle 数据库的 alert 日 志进行 跟踪处理,比如根据时间(天为单位),来查看和处理 ale

2、rt 日志。在未编写脚本时,常用的处理方法是,下载 alert 文件,使用文本编辑 工具查找,统计,定位,过滤,下载跟踪文件。一般比较费时,而且可能会有 遗漏。本文首先阐述算法,接着给出实现代码与样例,最后给出展望,脚本主 要包括 shell 脚本以及 sql 脚本。2.2. 算法算法图 1 流程图确定需要分析多少天以来的日志情况对时间进行处理,根据时间戳格式(本文处理的 alert 文件的时间格式类 似于:Fri Aug 1 13:22:37 2008),获取起始行号,分析从起始行号到结束的 所有内容。过滤所有的 ORA-信息,并对他们进行统计显示。对关键的错误信息(ORA-00600,OR

3、A-000060,ORA-1555,ORA-07445), 进行单独处理。查找并获取跟踪文件。生成 ftp 的格式,使用 ftp 命令下载跟踪文件。使用操作系统命令,获取错误对应的含义。3. ShellShell 代码代码 处理 alert 文件的调用脚本 check_alert.sh#!/bin/sh #设置 alert 日志文件的环境变量 ORIGINAL_ALERT=“/arraybill/home/oracle/app/oracle/admin/hnbill/bdump/ alert_hnbill.log“ #判断输入的参数:天 if $# -ne 1 then echo “参数不对,

4、用法: sh check_alert.sh 3 3“ exit 1 1 fi if $1 -lt 0 then echo “对不起,请输入一个非负整数“ exit 1 1 fi#查询参数对应时间以前的系统时间 sh dated_alert.sh $1 1 /dev/null #分解时间格式,注意,其中天可能是一位,也可能是两位,月份是 3 位,月份 与天组成的字符串长度固定 str_day=$(sed 1d tmp_date.log|awk if(substr($1,1,1) = 0) print substr($1,2,1);else print substr($1,1,2) ) str_l

5、ength=$(echo $str_day|awk print length($1) #将三个字母表示的月份分解成首字母大写,其他小写 str_month=$(sed 1d tmp_date.log|awk print substr($1,4,3)|sed 1,$y/JFMASODNABCDEFGHIJKLMNOPQRSTUVWXYZ/JFMASODNabcdefghijklmnop qrstuvwxyz/)if $str_length -eq 1 then echo “awk /“$str_month $str_day“/print NR “$ORIGINAL_ALERT“ tmp.sh #

6、echo “$str_month $str_day“fi if $str_length -eq 2 then echo “awk /“$str_month $str_day“/print NR “$ORIGINAL_ALERT“ tmp.sh #echo “$str_month $str_day“fichmod 777777 tmp.sh chmod 777777 tmp.sh sh tmp.sh |awk NR=1print $1 rownum.lst#获取要处理的 alert 日志的开始行号和结束行号 alert_row_begin=$(cat rownum.lst |awk print

7、$1) alert_row_end=$(wc -l $ORIGINAL_ALERT|awk print $1) echo “awk NR=$alert_row_begin,NR=$alert_row_endprint $0 “$ORIGINAL_ALERT“ tmp.sh#根据行号范围,截取 alert 日志内容,并保存到临时文件 tmp_alert.tmp 中sh tmp.sh tmp_alert.tmpecho echo “-“ echo “错误汇总 开始时间:$begin_date_time“ echo “-“ echoecho “数量 错误号“ echo “- -“ grep ORA-

8、 tmp_alert.tmp |awk print substr($0,0,9)|sort -nr| uniq -c|sort -nr#如果有 600 错误,调用 600 错误的处理脚本 if $(awk /ORA-00600/print NR tmp_alert.tmp|wc -l|awk print $1) -gt 0 then sh check_00600.sh fi #如果有 07445 错误,调用 07445 错误的处理脚本 if $(awk /ORA-07445/print NR tmp_alert.tmp|wc -l|awk print $1) -gt 0 then sh che

9、ck_07445.sh fi#如果有 000060000060 错误,调用 000060 错误的处理脚本if $(awk /ORA-000060/print NR tmp_alert.tmp|wc -l|awk print $1) -gt 0 then sh check_000060.sh fi#如果有 0155501555 错误,调用 01555 错误的处理脚本 if $(awk /ORA-01555/print NR tmp_alert.tmp|wc -l|awk print $1) -gt 0 then sh check_01555.sh fiecho #删除调用过程中产生的临时文件 r

10、m -f tmp_3_line.sh rm -f tmp_date.log rm -f tmp.sh rm -f ora01555_trc.log rm -f ora006000_trc.log rm -f ora07445_trc.log rm -f ora000060_trc.log rm -f trc_tmp rm -f tmp_alert.tmp rm -f ora006000_rownum.log rm -f rownum.lst产生格式化日期的脚本 dated_alert.shecho “set heading off“ get_date.sql echo “set feedbac

11、k off“ get_date.sql echo “set term off“ get_date.sql echo “spool tmp_date.log“ get_date.sql echo “select sysdate-“$1 1“ from dual;“ get_date.sqlecho “spool off“ get_date.sql echo “exit“ get_date.sqlexport NLS_LANG=americansqlplus “/as sysdba“ get_date.sql tmp1.sh chmod 777777 tmp1.sh chmod 777777 tm

12、p1.sh echo echo sh tmp1.sh |sort -r| uniq ora006000_trc.log #对所有的 ORA-00600 跟踪文件进行处理,去掉重复的文件,判断文件是否存在, 并生成 ftp 可用的格式 echo “ trc_tmp for trc_file in $(cat ora006000_trc.log|awk print $2) do if -f $trc_file then echo “mget $trc_file“ trc_tmp else echo “找不到跟踪文件: $trc_file“ trc_tmp fi done cat trc_tmp|s

13、ort -r echo echoecho tmp_3_line.sh chmod 777777 tmp_3_line.sh chmod 777777 tmp_3_line.sh#对于每个 ORA-0060000600,打印时间戳、跟踪文件和具体报错信息 for tmp_row_num in $(awk /ORA-00600/print NR tmp_alert.tmp)do let tmp_time=$tmp_row_num-2 2 let tmp_trc=$tmp_row_num-1 1 echo “awk NR=“$tmp_time“print $0 tmp_alert.tmp“ tmp_

14、3_line.sh echo “awk NR=“$tmp_trc“print $0 tmp_alert.tmp“ tmp_3_line.sh echo “awk NR=“$tmp_row_num“print $0 tmp_alert.tmp“ tmp_3_line.sh echo “echo“ tmp_3_line.sh donesh tmp_3_line.shecho echo#错误信息提示 echo “-“ echo “关于 ORA-0060000600“ echo “-“ oerr ora 0060000600 echo输出样例$ sh check_alert.sh 2 2 - 错误汇总 开始时间:Wed Sep 1010 0000:1111:3939 20082008 -数量 错误号 - - 3 3 ORA-0060000600 1 1 ORA-0155501555- ORA-0060000600 错误跟踪信息 -mget /arraybill/home/oracle/app/oracle/admin/hnbill/udump/hnbill_ora_5984.trc 找不到跟踪文件: /arraybill/home/oracle/app/oracle/admin/hnbill/udump/hnbill_ora_10650.t rcFri Sep

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号