ITPub博客

首页 > 数据库 > Oracle > shell脚本检查alert警告日志中是否存在ORA-错误

shell脚本检查alert警告日志中是否存在ORA-错误

原创 Oracle 作者:vage_fang 时间:2015-10-27 15:42:56 0 删除 编辑
     平时在检点的时候总是想着能不能让检点各个数据库的工作变得更有效率。shell无疑正是我目前要找的工具,可能有比shell更好的,python也不错,后续再继续学习。。
    以下是目前自己写的检点alert日志,现在是最初范本,目前只是为了实现目标不在乎优化,后面还得搞正规一点
[oracle@Primary shell]$ cat check_alert.sh

#! /bin/sh

export ORACLE_SID=orcl
sid=`echo $ORACLE_SID`

datetime=`env LANG=en_US.UTF-8 date -d '-1 day'`

datetime1=`echo ${datetime:0:10}`

len=`echo $datetime1|cut -d " " -f 3 |wc -L`
if [ "$len" -eq 1 ]; 
then
   datetime1=`echo $datetime1|cut -d " " -f 1,2`' 0'`echo $datetime1|cut -d " " -f 3`
else
   datetime1=$datetime1
fi

#echo $datetime1
file_name=`sqlplus -s "/ as sysdba" << EOF_SQLPLUS
set pagesize 0 feedback off verify off heading off echo off
select value||'/alert_'||'$sid'||'.log' from v\\\$diag_info where name='Diag Trace';
exit;
END`

#echo $datetime1
#echo $file_name
row=`grep -n "$datetime1" $file_name | sed -n '1p;1q' | cut -d ':' -f 1`

#echo $row
contents=`tail -n +$row $file_name|grep -C 5 'ORA'`
echo "$contents"

谨以此学习

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28473562/viewspace-1816628/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oracle周别疑问
请登录后发表评论 登录
全部评论

注册时间:2013-05-01

  • 博文量
    16
  • 访问量
    75213