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

     平时在检点的时候总是想着能不能让检点各个数据库的工作变得更有效率。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博客 ” ,链接:http://blog.itpub.net/28473562/viewspace-1816628/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28473562/viewspace-1816628/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值