一个监控oracle数据库某个字段值变化并发送邮件报警的脚本

  talk is cheap,here is the code:

#!/bin/sh
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1/
export PATH=$PATH:$ORACLE_HOME/bin
export base_path=/home/peteryrcc/code/database

sqlplus account/'password'@10.75.65.142:1521/database name <<EOF
spool /home/peteryrcc/code/database/current_dmtc.log
@/home/peteryrcc/code/database/dmtc_monitoring.sql
spool off
EOF

export current=$base_path/current_dmtc.log
export historical=$base_path/historical_dmtc.log

grep 'NEW' $current>/dev/null
if [ $? -ne 0 ];then
        grep 'NEW' $historical>/dev/null
        if [ $? -ne 0 ];then
                echo 'no found all the time'
        else
                cat $current>$historical
                echo $(date)-------"no found !">>$base_path/dmtc_monitoring.log
                echo 'the DMTC status has been turn to completed, please perform the update'|mail -s "DOCTOR_MODEL_TYPE_CODE issue! " peteryang.rcc@cn.luxottica.com Amy.Xiong@cn.luxottica.com

        fi
else
        grep 'NEW' $historical>/dev/null
        if [ $? -eq 0 ];then
                echo 'found all the time'
        else
                cat $current>$historical
                echo $(date)-------"found DMTC=11">>$base_path/dmtc_monitoring.log
                cat $current|grep -v SQL|mail -s "DOCTOR_MODEL_TYPE_CODE issue! " peteryang.rcc@cn.luxottica.com Amy.Xiong@cn.luxottica.com
        fi
fi

 

转载于:https://www.cnblogs.com/peter1994/p/7514671.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值