爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      监控脚本

      首页 知识中心 其他 文章详情页

      监控脚本

      2024-12-16 08:18:54 阅读次数:22

      监控,脚本

      1、检查CPU使用率是否超过90%
      [oracle@hisdb1 ~]$ vi chk_cpu.sh
      #!/bin/bash
      MT_HOME="/home/oracle/monitor"
      vmstat_file="$MT_HOME/tmp/vmstat.txt"
      dt=`date +%Y%m%d_%H:%M:%S`
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      vmstat 1 10 > $vmstat_file
      cat $vmstat_file | tail -10 | awk '{print $(NF-2)}' > /tmp/cpuage.txt
      for i in `cat /tmp/cpuage.txt | sed -e 's/\r//g'`
      do
        if [[ $i -le 10 ]];then
        count=$((count+1))
        fi
      done
      
      if [[ $count -ge 10 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of CPU exceeds 90% for 10s from $dt."
      else
         output=0
         echo "The usage of CPU is normal for 10s from $dt."
      fi
      exit 0
      
      2、SWAP空间一般空闲,若使用超过20%,则有异常
      [oracle@hisdb1 ~]$ vi chk_swap.sh
      #!/bin/bash
      MT_HOME="/home/oracle/monitor"
      swap_file="$MT_HOME/tmp/swap_file.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      free -m > $swap_file
      used_size=`cat $swap_file | grep "Swap" | awk -F' ' '{print \$3}' | sed -e 's/\r//g'`
      total_size=`cat $swap_file | grep "Swap" | awk -F' ' '{print \$2}' | sed -e 's/\r//g'`
      pct=`echo "scale=2; $used_size / $total_size" | bc`
      if [[ $pct > 0.2 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of Swap is higher than 20%."
      else
         output=0
         echo "The usage of Swap is normal!"
      fi
      exit 0
      
      3、表空间使用率超97%
      [oracle@hisdb1 ~]$ vi chk_tbs.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      DT=$(date '+%Y-%m-%d %H:%M:%S')
      pdbs="$MT_HOME/tmp/pdbs.txt"
      tabspace_data="$MT_HOME/tmp/tabspace_data.txt"
      max_tab_num="$MT_HOME/tmp/max_tab_num.txt"
      max_tablespace="$MT_HOME/tmp/max_tablespace.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      test -f $tabspace_data && >$tabspace_data
      test -f $max_tablespace && >$max_tablespace
      SMON_COUNT=`ps -ef | grep smon | grep -c $ORACLE_SID`
      
      if (( $SMON_COUNT > 0 ));then
      sqlplus -S / as sysdba <<EOF > $pdbs
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      show pdbs
      EOF
      pdbname=`cat $pdbs | awk '{print $2}'`
      
      jud_pdb=`cat $pdbs | grep -iw "PDB$SEED" | wc -l`
      if [[ $jud_pdb -eq 1 ]];then
      echo "The following is CDB's data." >> $tabspace_data
      sqlplus -S / as sysdba <<EOF >> $tabspace_data
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select tablespace_name || '-' || PCT
      from 
      (select a.*,round(PCT_MAX2CURR*PCT_CURR2USED/100) PCT 
        from (SELECT D.TABLESPACE_NAME,G.BLOCK_SIZE,
              DECODE(MAX_SIZE_MB, 0, SPACE, MAX_SIZE_MB) MAX_SIZE_MB,
              SPACE CURR_SIZE_MB,
              SPACE - NVL(FREE_SPACE, 0) USED_SIZE_MB,
              DECODE(FREE_SPACE,NULL,0,FREE_SPACE) FREE_SIZE_MB,
              ROUND(SPACE/DECODE(MAX_SIZE_MB, 0, SPACE, MAX_SIZE_MB)*100, 3) PCT_MAX2CURR,
              ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 3) PCT_CURR2USED
               FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024)) SPACE,
                 ROUND(SUM(DECODE(MAXBYTES,0,BYTES,MAXBYTES) / 1024 / 1024)) MAX_SIZE_MB
            FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) D,
         (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024)) FREE_SPACE
            FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F,
         DBA_TABLESPACES G
      WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) AND D.TABLESPACE_NAME = G.TABLESPACE_NAME
      ORDER BY PCT_MAX2CURR*PCT_CURR2USED desc) a)
       where rownum=1;
      EOF
      
      for i in `echo $pdbname`
      do
      echo "The following is the PDB $i's data." >> $tabspace_data
      sqlplus -S / as sysdba <<EOF >> $tabspace_data
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      alter session set container=$i;
      select tablespace_name || '-' || PCT
      from 
      (select a.*,round(PCT_MAX2CURR*PCT_CURR2USED/100) PCT 
        from (SELECT D.TABLESPACE_NAME,G.BLOCK_SIZE,
              DECODE(MAX_SIZE_MB, 0, SPACE, MAX_SIZE_MB) MAX_SIZE_MB,
              SPACE CURR_SIZE_MB,
              SPACE - NVL(FREE_SPACE, 0) USED_SIZE_MB,
              DECODE(FREE_SPACE,NULL,0,FREE_SPACE) FREE_SIZE_MB,
              ROUND(SPACE/DECODE(MAX_SIZE_MB, 0, SPACE, MAX_SIZE_MB)*100, 3) PCT_MAX2CURR,
              ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 3) PCT_CURR2USED
               FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024)) SPACE,
                 ROUND(SUM(DECODE(MAXBYTES,0,BYTES,MAXBYTES) / 1024 / 1024)) MAX_SIZE_MB
            FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) D,
         (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024)) FREE_SPACE
            FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F,
         DBA_TABLESPACES G
      WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) AND D.TABLESPACE_NAME = G.TABLESPACE_NAME
      ORDER BY PCT_MAX2CURR*PCT_CURR2USED desc) a)
       where rownum=1;
      EOF
      done
      
      else
      echo "This is non_CDB circumstances and the following is max tablespace usage detail." >> $tabspace_data
      sqlplus -S / as sysdba <<EOF >> $tabspace_data
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select tablespace_name || '-' || PCT
      from 
      (select a.*,round(PCT_MAX2CURR*PCT_CURR2USED/100) PCT 
        from (SELECT D.TABLESPACE_NAME,G.BLOCK_SIZE,
              DECODE(MAX_SIZE_MB, 0, SPACE, MAX_SIZE_MB) MAX_SIZE_MB,
              SPACE CURR_SIZE_MB,
              SPACE - NVL(FREE_SPACE, 0) USED_SIZE_MB,
              DECODE(FREE_SPACE,NULL,0,FREE_SPACE) FREE_SIZE_MB,
              ROUND(SPACE/DECODE(MAX_SIZE_MB, 0, SPACE, MAX_SIZE_MB)*100, 3) PCT_MAX2CURR,
              ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 3) PCT_CURR2USED
               FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024)) SPACE,
                 ROUND(SUM(DECODE(MAXBYTES,0,BYTES,MAXBYTES) / 1024 / 1024)) MAX_SIZE_MB
            FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) D,
         (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024)) FREE_SPACE
            FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F,
         DBA_TABLESPACES G
      WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) AND D.TABLESPACE_NAME = G.TABLESPACE_NAME
      ORDER BY PCT_MAX2CURR*PCT_CURR2USED desc) a)
       where rownum=1;
      EOF
      fi
      
      else
        output=1
        echo -e "\033[31mAttention,please!\033[0mDB has some problem, please check it!"
        exit 1
      fi
      
      cat $tabspace_data | grep "-" | awk -F'-' '{print $2}' | grep -v "^$" >$max_tab_num
      for j in `cat $max_tab_num | sed -e 's/\r//g'`
      do
         if [[ $j -ge 97 ]];then
               count=$((count+1))
      		 cat $tabspace_data | grep $j -B1 >> $max_tablespace
         fi
      done
      
      max_num=`cat $tabspace_data | awk -F'-' '{print $2}' | sort -rn | head -1 | sed -e 's/\r//g'`
      if [[ $count -gt 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe max usage of some tablespaces is higher than 97%, please check it!"
         echo ""
         cat $max_tablespace
      else
         output=0
         echo "The usage of tablespace is \033[32mnormal\033[0m at $DT,the following is the max usage of tablespace."
         echo ""
         cat $tabspace_data | grep $max_num -B1
      fi
      
      exit 0 
      
      4、检查是否有失效的分区索引
      [oracle@hisdb1 scripts]$  vi chk_part_ind.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      DT=$(date '+%Y-%m-%d %H:%M:%S')
      pdbs="$MT_HOME/tmp/pdbs.txt"
      ord_part_num="$MT_HOME/tmp/ord_part_num.txt"
      ind_part_detail="$MT_HOME/tmp/ind_part_detail.txt"
      ind_sub_part_detail="$MT_HOME/tmp/ind_sub_part_detail.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      test -f $ord_part_num && >$ord_part_num
      test -f $ind_part_detail && >$ind_part_detail
      sqlplus -S / as sysdba <<EOF > $pdbs
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      show pdbs
      EOF
      pdbname=`cat $pdbs | awk '{print $2}'`
      
      jud_pdb=`cat $pdbs | grep -iw "PDB$SEED" | wc -l`
      if [[ $jud_pdb -eq 0 ]];then
      sqlplus -S / as sysdba <<EOF >> $ord_part_num
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select decode(count(*),-1,min('index+'||index_owner||'.'||index_name||'+unusable,partition_name+'||partition_name),count(*)) from dba_ind_partitions where status not in ('USABLE','N/A');
      EOF
      
      echo "The partition index detail of traditional database as below." >> $ind_part_detail
      echo "INDEX_OWNER               INDEX_NAME                                         PARTITION_NAME"  >> $ind_part_detail
      sqlplus -S / as sysdba <<EOF >> $ind_part_detail
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col INDEX_OWNER for a25;
      col INDEX_NAME for a50;
      col PARTITION_NAME for a25;
      select index_owner,index_name,partition_name from dba_ind_partitions where status not in ('USABLE','N/A'); 
      EOF
      echo "" >> $ind_part_detail
      
      trad_num=`cat $ind_part_detail | wc -l`
      if [[ $trad_num -eq 3 ]];then
         >$ind_part_detail
      fi
      else
      sqlplus -S / as sysdba <<EOF >> $ord_part_num
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select decode(count(*),-1,min('index+'||index_owner||'.'||index_name||'+unusable,partition_name+'||partition_name),count(*)) from dba_ind_partitions where status not in ('USABLE','N/A');
      EOF
      
      echo "The partition index detail of CDB as below." >> $ind_part_detail
      echo "INDEX_OWNER               INDEX_NAME                                         PARTITION_NAME"  >> $ind_part_detail
      sqlplus -S / as sysdba <<EOF >> $ind_part_detail
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col INDEX_OWNER for a25;
      col INDEX_NAME for a50;
      col PARTITION_NAME for a25;
      select index_owner,index_name,partition_name from dba_ind_partitions where status not in ('USABLE','N/A'); 
      EOF
      echo "" >> $ind_part_detail
      
      cdb_num=`cat $ind_part_detail | wc -l`
      if [[ $cdb_num -eq 3 ]];then
         >$ind_part_detail
      fi
      
      for i in `echo $pdbname`
      do
      sqlplus -S / as sysdba <<EOF >> $ord_part_num
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      alter session set container=$i;
      select decode(count(*),-1,min('index+'||index_owner||'.'||index_name||'+unusable,partition_name+'||partition_name),count(*)) from dba_ind_partitions where status not in ('USABLE','N/A');
      EOF
      done
      
      for i in `echo $pdbname`
      do
      echo "The partition index detail of PDB $i as below." >> $ind_sub_part_detail
      echo "INDEX_OWNER               INDEX_NAME                                         PARTITION_NAME" >> $ind_sub_part_detail
      sqlplus -S / as sysdba <<EOF >> $ind_sub_part_detail
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col INDEX_OWNER for a25;
      col INDEX_NAME for a50;
      col PARTITION_NAME for a25;
      alter session set container=$i;
      select index_owner,index_name,partition_name from dba_ind_partitions where status not in ('USABLE','N/A') order by partition_name; 
      EOF
      echo "" >> $ind_sub_part_detail
      pdb_num=`cat $ind_sub_part_detail | wc -l`
      if [[ $pdb_num -eq 3 ]];then
         >$ind_sub_part_detail
      else
         cat $ind_sub_part_detail >> $ind_part_detail
         >$ind_sub_part_detail
      fi
      done
      fi
      
      ord_ind_invalid=`awk '{sum+=$1}END{print sum}' $ord_part_num`
      if [[ $ord_ind_invalid > 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThere are some invalid partition indexes in database.The following is the detail."
         echo ""
         cat $ind_part_detail
      else
         output=0
         echo "Don't worry,the database doesn't have any invalid partition index."
      fi
      exit 0
         
      5、检查是否有失效的普通索引
      [oracle@hisdb1 scripts]$  vi chk_ord_ind.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      DT=$(date '+%Y-%m-%d %H:%M:%S')
      pdbs="$MT_HOME/tmp/pdbs.txt"
      ord_ind_num="$MT_HOME/tmp/ord_ind_num.txt"
      ind_ord_detail="$MT_HOME/tmp/ind_ord_detail.txt"
      ind_sub_ord_detail="$MT_HOME/tmp/ind_sub_ord_detail.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      test -f $ord_ind_num && >$ord_ind_num
      test -f $ind_ord_detail && >$ind_ord_detail
      test -f $ind_sub_ord_detail && >$ind_sub_ord_detail
      
      sqlplus -S / as sysdba <<EOF > $pdbs
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      show pdbs
      EOF
      pdbname=`cat $pdbs | awk '{print $2}'`
      
      jud_pdb=`cat $pdbs | grep -iw "PDB$SEED" | wc -l`
      if [[ $jud_pdb -eq 0 ]];then
      sqlplus -S / as sysdba <<EOF >> $ord_ind_num
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select decode(count(*),-1,min('index+'||a.owner||'.'||a.index_name||'+unusable,table+'||a.table_owner||','||a.table_name),count(*)) from dba_indexes a where a.status not in ('VALID','N/A');
      EOF
      
      echo "The invalid ordinary index detail of traditional database as below." >> $ind_ord_detail
      echo "OWNER                     TABLE_NAME                     INDEX_NAME"  >> $ind_ord_detail
      sqlplus -S / as sysdba <<EOF >> $ind_ord_detail
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col owner for a25;
      col index_name for a50;
      col table_name for a30;
      select owner,table_name,index_name from dba_indexes where status not in ('N/A','VALID');
      EOF
      echo "" >> $ind_ord_detail
      
      trad_num=`cat $ind_ord_detail | wc -l`
      if [[ $trad_num -eq 3 ]];then
         >$ind_ord_detail
      fi
      
      else
      sqlplus -S / as sysdba <<EOF >> $ord_ind_num
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select decode(count(*),-1,min('index+'||a.owner||'.'||a.index_name||'+unusable,table+'||a.table_owner||','||a.table_name),count(*)) from dba_indexes a where a.status not in ('VALID','N/A');
      EOF
      
      for i in `echo $pdbname`
      do
      sqlplus -S / as sysdba <<EOF >> $ord_ind_num
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      alter session set container=$i;
      select decode(count(*),-1,min('index+'||a.owner||'.'||a.index_name||'+unusable,table+'||a.table_owner||','||a.table_name),count(*)) from dba_indexes a where a.status not in ('VALID','N/A');
      EOF
      done
      
      echo "The invalid ordinary index detail of CDB as below." >> $ind_ord_detail
      echo "OWNER                     TABLE_NAME                     INDEX_NAME"  >> $ind_ord_detail
      sqlplus -S / as sysdba <<EOF >> $ind_ord_detail
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col owner for a25;
      col index_name for a50;
      col table_name for a30;
      select owner,table_name,index_name from dba_indexes where status not in ('N/A','VALID');
      EOF
      echo "" >> $ind_ord_detail
      
      cdb_num=`cat $ind_ord_detail | wc -l`
      if [[ $cdb_num -eq 3 ]];then
         >$ind_ord_detail
      fi
      
      for i in `echo $pdbname`
      do
      echo "The invalid ordinary index detail of PDB $i as below." >> $ind_sub_ord_detail
      echo "OWNER                     TABLE_NAME                     INDEX_NAME"  >> $ind_sub_ord_detail
      sqlplus -S / as sysdba <<EOF >> $ind_sub_ord_detail
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col owner for a25;
      col index_name for a50;
      col table_name for a30;
      alter session set container=$i;
      select owner,table_name,index_name from dba_indexes where status not in ('N/A','VALID');
      EOF
      echo "" >> $ind_sub_ord_detail
      
      pdb_num=`cat $ind_sub_ord_detail | wc -l`
      if [[ $pdb_num -eq 3 ]];then
         >$ind_sub_ord_detail
      else
         cat $ind_sub_ord_detail >> $ind_ord_detail
         >$ind_sub_ord_detail
      fi
      done
      fi
      
      ord_ind_invalid=`awk '{sum+=$1}END{print sum}' $ord_ind_num`
      if [[ $ord_ind_invalid > 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThere are some invalid ordinary indexes in database.The following is the detail."
         echo ""
         cat $ind_ord_detail
      else
         output=0
         echo "Don't worry,the database doesn't have invalid ordinary index."
      fi
      exit 0
      
      6、检查数据文件数量是否低于DB_FILES参数值的90%
      [oracle@hisdb1 scripts]$ vi chk_dbfile.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      total_dbfile="$MT_HOME/tmp/total_dbfile.txt"
      pdbs="$MT_HOME/tmp/pdbs.txt"
      pdbs_dbfile="$MT_HOME/tmp/pdbs_dbfile.txt"
      db_dbfile="$MT_HOME/tmp/db_dbfile.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      sqlplus -S / as sysdba <<EOF > $total_dbfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      show parameter db_files
      EOF
      sys_dbfile_num=`cat $total_dbfile | awk '{print $3}' | sed -e 's/\r//g'`
      
      sqlplus -S / as sysdba <<EOF > $pdbs
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      show pdbs
      EOF
      pdbname=`cat $pdbs | awk '{print $2}'`
      
      jud_pdb=`cat $pdbs | grep -iw "PDB$SEED" | wc -l`
      if [[ $jud_pdb -eq 0 ]];then
      sqlplus -S / as sysdba <<EOF >$db_dbfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select count(*) from dba_data_files;
      EOF
      
      echo 0 >$pdbs_dbfile
      else
      for i in `echo $pdbname`
      do
      sqlplus -S / as sysdba <<EOF >> $pdbs_dbfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      alter session set container=$i;
      select count(*) from dba_data_files;
      EOF
      done
      
      sqlplus -S / as sysdba <<EOF >$db_dbfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select count(*) from dba_data_files;
      EOF
      fi
      
      db_file=`cat $db_dbfile | sed -e 's/\r//g'`
      pdb_file=`awk '{sum+=$1}END{print sum}' $pdbs_dbfile`
      total_dbfiles=`echo "$db_file+$pdb_file" | bc`
      
      dbfile_rate=`echo "scale=2; $total_dbfiles / $sys_dbfile_num" | bc`
      dbfile_perc=`echo "scale=2; $dbfile_rate * 100" | bc`
      if [[ $dbfile_perc > 89 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of dbfile is higher than 90%."
         echo -e "The value of the system setting is $sys_dbfile_num,and $total_dbfiles are currently used,so the usage rates is \033[31m$dbfile_perc%\033[0m."
      else
         output=0
         echo "The usage of dbfile is \033[32mnormal\033[0m!"
         echo -e "The value of the system setting is $sys_dbfile_num,and $total_dbfiles are currently used,so the usage rates is \033[31m$dbfile_perc%\033[0m."
      fi
      exit 0
      
      7、查看资源是否是online,特别是db、listener、vip、asm磁盘等资源,若出现offline,则有异常
      [grid@hisdb1 scripts]$ vi chk_gires.sh
      #!/bin/bash
      source /home/grid/.bash_profile
      MT_HOME="/home/grid/monitor"
      dt=`date +%Y%m%d_%H:%M:%S`
      asmdiskname="$MT_HOME/tmp/asmdisk.dat"
      gi_status="$MT_HOME/tmp/gi_status.txt"
      rac_status="$MT_HOME/tmp/rac_status.txt"
      dbname="$MT_HOME/tmp/dbname.txt"
      vip_list="$MT_HOME/tmp/vip_list.txt"
      #htname=`hostname`
      #hostname_length=`expr length $htname`
      #res_length=`echo "$hostname_length-1" | bc`
      #sim_htname=`echo $htname | cut -c1-$res_length`
      test -d /home/grid/monitor/tmp || mkdir -p /home/grid/monitor/tmp 
      test -f $rac_status || touch $rac_status && >$rac_status
      
      if [ `ps -ef | grep d.bin | wc -l` -gt 15 ];then
      sqlplus -S / as sysdba <<EOF > $asmdiskname
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select name from v\$asm_diskgroup; 
      EOF
      
      test -f $gi_status && >$gi_status
      for i in `cat $asmdiskname`
      do
      /u01/app/19.13/grid/bin/crsctl stat res -t -w "((NAME = ora.$i.dg))"  | cut -c16-67 | grep -v "^$" | grep -i line >> $gi_status
      /u01/app/19.13/grid/bin/crsctl stat res -t -w "((NAME = ora.$i.dg))" | tail -n +6 >> $rac_status
      done
      
      /u01/app/19.13/grid/bin/crsctl stat res -t | grep "ora.*.vip$" | awk -F'.' '{print $2}' >$vip_list
      for j in `cat $vip_list`
      do
      /u01/app/19.13/grid/bin/crsctl stat res -t -w "((NAME = ora.$))"  | cut -c16-67 | grep -v "^$" | grep -i line >> $gi_status
      /u01/app/19.13/grid/bin/crsctl stat res -t -w "((NAME = ora.$))" | tail -n +6 >> $rac_status
      done
      
      /u01/app/19.13/grid/bin/crsctl stat res -t | grep "ora.*.db$" | awk -F'.' '{print $2}' >$dbname
      for m in `cat $dbname`
      do
      /u01/app/19.13/grid/bin/crsctl stat res -t -w "((NAME = ora.$m.db))"  | cut -c16-67 | grep -v "^$" | grep -i line >> $gi_status
      /u01/app/19.13/grid/bin/crsctl stat res -t -w "((NAME = ora.$m.db))" | tail -n +6 >> $rac_status
      done
      
      abno_data=`cat $gi_status | grep -viE "STABLE|Open" | wc -l`
      if [[ $abno_data -gt 0 ]];then
         output=1
         echo -e "\033[31mAttention!\033[0mRAC has some problem, please check it!"
         echo ""
         echo "The following is the abnormal detail."
         cat $rac_status | grep -viE "STABLE|Open" | grep OFFLINE -C1
      else
         output=0
         echo "RAC resource is good!"
      fi
      
      else
        output=1
        echo -e "\033[31mAttention!\033[0mThe quantity of GI's process is less than normal level, please check it!"
      fi
      
      exit 0
      
      8、目录使用率超过90%,则需处理
      [oracle@hisdb1 scripts]$ vi chk_disk.sh
      #!/bin/bash
      MT_HOME="/home/oracle/monitor"
      diskusage="$MT_HOME/tmp/diskusage.txt"
      sdisk_data="$MT_HOME/tmp/sdisk_data.txt"
      abn_diskusage="$MT_HOME/tmp/abn_diskusage.txt"
      mid_abn_diskusage="$MT_HOME/tmp/mid_abn_diskusage.txt"
      fina_abn_diskusage="$MT_HOME/tmp/fina_abn_diskusage.txt"
      sam_diskusage="$MT_HOME/tmp/sam_diskusage.txt"
      tmp_diskusage="$MT_HOME/tmp/tmp_diskusage.txt"
      jud_inum="$MT_HOME/tmp/jud_inum.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp 
      test -f $abn_diskusage || touch $abn_diskusage && >$abn_diskusage
      test -f $jud_inum || touch $jud_inum && >$jud_inum
      test -f $tmp_diskusage || touch $tmp_diskusage
      dt=`date +%Y%m%d_%H:%M:%S`
      df -h > $diskusage
      cat $diskusage | tail -n +2 | awk '{print $(NF-1),$NF}' | sed 's/%//g' > $sdisk_data
      
      for i in `cat $sdisk_data | awk '{print $1}' | sed -e 's/\r//g'`
      do
      if [[ $i -ge 90 ]];then
         #diskname=`cat /tmp/cpuage.txt | grep $i | awk '{print $2}' | head -1`
         #echo -e "\033[31mAttention,please!\033[0mThe usage of $diskname exceeds 90% at $dt."
         count=$((count+1))
         jud_idt=`cat $sdisk_data | grep -i $i | wc -l`
         if [[ $jud_idt -gt 1 ]];then
             echo $i >> $jud_inum
         else
            cat $sdisk_data | grep -i $i >> $abn_diskusage
         fi
         #cat $diskusage | awk '{print $(NF-1),$NF}' | grep -i $i > $sam_diskusage  
         #diff_num=`diff $sam_diskusage $tmp_diskusage | wc -l`
         #>$tmp_diskusage
         #cat $sam_diskusage >> $tmp_diskusage
         #if [[ $diff_num -gt 0 ]];then
         #   cat $sam_diskusage >> $abn_diskusage
         #else :
         #fi
      fi
      done
      
      for j in `cat $jud_inum | sort | uniq`
      do
       cat $sdisk_data | grep -i $j >> $abn_diskusage
      done
      
      test -f $mid_abn_diskusage && >$mid_abn_diskusage
      test -f $fina_abn_diskusage && >$fina_abn_diskusage
      sed 's/^/ /' $abn_diskusage >>$mid_abn_diskusage
      sed '1i\Use% Mounted on' $mid_abn_diskusage >>$fina_abn_diskusage
      
      #usage=`cat $abn_diskusage | awk '{print $1}'`
      #mountdir=`cat $abn_diskusage | awk '{print $2}'`
      
      if [[ $count -gt 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of DISK exceeds 90% at $dt."
         echo ""
         echo "Here is the out of standard usage details,please check it."
         cat $fina_abn_diskusage
      else
         output=0
         echo -e "The usage of disk is \033[32mnormal\033[0m at $dt."
      fi
      
      exit 0
      
      9、对比平常进程数量,出现突增的情况则有异常
      [oracle@hisdb1 scripts]$ vi chk_process.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      processfile="$MT_HOME/tmp/process.dat"
      dt=`date +%Y%m%d_%H:%M:%S`
      sqlplus -S / as sysdba <<EOF > $processfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col value for a20
      select a.sessions,b.value,round(a.sessions/b.value*100,2) as zhanyong from (select count(*) sessions from v\$session ) a, (select value from v\$parameter where name='processes') b;
      EOF
      
      RAT=`cat $processfile | tail -1 | awk '{print $NF}' | sed -e 's/\r//g'`
      SESSIONS=`cat $processfile | tail -1 | awk '{print $1}'`
      VALUE=`cat $processfile | tail -1 | awk '{print $2}'`
      
      if [[ $RAT > 89 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe utilization rate of current process exceeds 90% at $dt."
         echo ""
         echo "The following is the detail of process status."
         echo "The value of the system setting is $VALUE,and $SESSIONS are currently used."
      else
         output=0
         echo -e "The utilization rate of current process is \033[32mnormal\033[0m at $dt"
         echo ""
         echo "The following is the detail of process status."
         echo "The value of the system setting is $VALUE,and $SESSIONS are currently used."
      fi
      
      exit 0
      
      10、检查监听启动时间是否正常,若无监听或未注册则异常
      [oracle@hisdb1 scripts]$ vi chk_listener.sh 
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      listener_status="$MT_HOME/tmp/listener_status.txt"
      dt=`date +%Y%m%d_%H:%M:%S`
      SMON_COUNT=`ps -ef | grep smon | grep -c $ORACLE_SID`
      if (( $SMON_COUNT > 0 ));then
         lsnrctl status > $listener_status
      else
         output=1
         echo -e "\033[31mAttention,please!\033[0mDB has some problem, please check it!"
         exit 1
      fi
      
      count=`cat $listener_status | grep $ORACLE_SID | wc -l`
      if [[ $count -eq 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe status of listener is abnormal at $dt."
      else
         output=0
         echo -e "The status of listener is \033[32mnormal\033[0m at $dt."
      fi
      
      exit 0
      
      11、检查主备库磁盘组使用情况,使用率超过85%显示异常
      [oracle@hisdb1 tmp]$ vi chk_asmdisk.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      asmdiskfile="$MT_HOME/tmp/asmdiskfile.txt"
      asmdisk="$MT_HOME/tmp/asmdisk.txt"
      abn_diskgroup="$MT_HOME/tmp/abn_diskgroup.txt"
      fina_abn_diskgroup="$MT_HOME/tmp/fina_abn_diskgroup.txt"
      jud_inum="$MT_HOME/tmp/jud_inum.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      test -f $jud_inum || touch $jud_inum && >$jud_inum
      dt=`date +%Y%m%d_%H:%M:%S`
      sqlplus -S / as sysdba <<EOF > $asmdiskfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      col name for a15;
      select name,total_mb/1024 total_gb,trunc(free_mb/1024) free_gb,trunc((total_mb-free_mb)/total_mb*100) "use%" from v\$asm_diskgroup; 
      EOF
      
      test -f $abn_diskgroup || >$abn_diskgroup
      cat $asmdiskfile | awk '{print $NF}' > $asmdisk
      for i in `cat $asmdisk | sed -e 's/\r//g'`
      do
      if [[ $i -ge 85 ]];then
         count=$((count+1))
         jud_idt=`cat $asmdiskfile | grep -i $i | wc -l`
         if [[ $jud_idt -gt 1 ]];then
             echo $i >> $jud_inum
         else
             cat $asmdiskfile | grep -i $i >> $abn_diskgroup
         fi
      fi
      done
      
      for j in `cat $jud_inum | sort | uniq`
      do
       cat $asmdiskfile | grep -i $j >> $abn_diskgroup
      done
      
      test -f $fina_abn_diskgroup || touch $fina_abn_diskgroup
      test -f $fina_abn_diskgroup && >$fina_abn_diskgroup
      sed '1i\NAME                 TOTAL_GB    FREE_GB     use%' $abn_diskgroup >>$fina_abn_diskgroup
      if [[ $count -gt 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of asmdisk exceeds 85% at $dt."
         echo ""
         echo "Here is the out of standard usage details,please check it."
         cat $fina_abn_diskgroup
      else
         output=0
         echo "The usage of asmdisk is normal at $dt."
      fi
      
      exit 0
      
      12、检查归档目录使用率是否正常(增加归档使用率),使用率超过85%显示异常.
      [oracle@hisdb1 scripts]$ vi chk_archdisk.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      archfile="$MT_HOME/tmp/archfile.txt"
      asmdiskfile="$MT_HOME/tmp/asmdiskfile.txt"
      recofile="$MT_HOME/tmp/recofile.txt"
      db_reco_dt="$MT_HOME/tmp/db_reco_dt.txt"
      diskusage="$MT_HOME/tmp/diskusage.txt"
      dt=`date +%Y%m%d_%H:%M:%S`
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      df -h >$diskusage
      
      sqlplus -S / as sysdba <<EOF > $archfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      archive log list;
      EOF
      
      sqlplus -S / as sysdba <<EOF > $recofile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      show parameter recovery;
      EOF
      
      cat $recofile | grep -w db_recovery_file_dest | awk '{print $3}' >$db_reco_dt
      
      arch_stat=`cat $archfile | grep -iw "Archive Mode" | wc -l`
      if [[ ${arch_stat} -eq 1 ]]
      then
        arch_jud=`cat $archfile | grep -iw "Archive destination" | grep "+" | wc -l`
      else
        echo "The DB is running in non-archive mode!"
        exit 1
      fi
      
      use_db_situ=`cat $archfile | grep -i USE_DB_RECOVERY_FILE_DEST | wc -l`
      db_reco_file_dest=`cat $recofile | grep -i db_recovery_file_dest | grep "+" | wc -l`
      
      if [[ $use_db_situ -eq 1 ]] && [[ $db_reco_file_dest -eq 1 ]] || [[ $arch_jud -eq 1 ]];then
      sqlplus -S / as sysdba <<EOF > $asmdiskfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select name,total_mb/1024 total_gb,trunc(free_mb/1024) free_gb,trunc((total_mb-free_mb)/total_mb*100) "use%" from v\$asm_diskgroup; 
      EOF
      
      if [[ $use_db_situ -eq 1 ]] && [[ $db_reco_file_dest -eq 1 ]];then
         archdisk=`cat $recofile | grep -iw "db_recovery_file_dest" | awk -F'+' '{print $NF}'`
         else
         archdisk=`cat $archfile | grep -iw "Archive destination" | awk -F'+' '{print $NF}'`
      fi
      
      archrat=`cat $asmdiskfile | awk '{print $(NF-3),$NF}' | grep $archdisk | awk '{print $NF}' | sed -e 's/\r//g'`
      arch_dest=`cat $asmdiskfile | awk '{print $1}' | grep $archdisk`
      
      if [[ $archrat -gt 85 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of archive destination exceeds 85% at $dt."
         echo ""
         echo "The following is the usage detail of archive directory."
         echo -e "The archive destination is $arch_dest,and the usage is \033[31m$archrat%\033[0m."
      else
         output=0
         echo -e "The usage of archive directory is \033[32mnormal\033[0m at $dt."
      fi
      
      elif [[ $use_db_situ -eq 1 ]] && [[ $db_reco_file_dest -eq 0 ]] || [[ $arch_jud -eq 0 ]];then
      if [[ $use_db_situ -eq 1 ]] && [[ $db_reco_file_dest -eq 0 ]];then
         archdisk01=`cat $recofile | grep -iw "db_recovery_file_dest" | awk '{print $3}'`
         else
         archdisk01=`cat $archfile | grep -iw "Archive destination" | awk '{print $3}'`
      fi
      
      mid_archdisk=`echo $archdisk01 | awk -F'/' '{print $2}'`
      filesys_usage=`cat $diskusage | grep -iw $mid_archdisk | awk '{print $(NF-1)}' | sed 's/%//g' | sed -e 's/\r//g'`
      #arch_dest01=`cat $diskusage | grep -iw $mid_archdisk | awk '{print $(NF)}'`
      if [[ $filesys_usage -gt 85 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe usage of archive destination exceeds 85% at $dt."
         echo ""
         echo "The following is the usage detail of archive directory."
         echo -e "The archive destination is $archdisk01,and usage is \033[31m$filesys_usage%\033[0m."
      else
         output=0
         echo -e "The usage of archive directory is \033[32mnormal\033[0m at $dt."
      fi
      fi
      exit 0
      
      13、查看RMAN备份情况,若最后一次备份失败,则异常(此项重要务必每天检查)
      [oracle@leo-oel150 scripts]$ vi chk_backup.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      backupfile="$MT_HOME/tmp/backupfile.txt"
      fina_backupfile="$MT_HOME/tmp/fina_backupfile.txt"
      dt=`date +%Y%m%d_%H:%M:%S`
      test -f $backupfile && >$backupfile
      test -f $fina_backupfile && >$fina_backupfile
      for i in 'DB FULL' 'DB INCR' 'DATAFILE FULL' 'DATAFILE INCR' 'ARCHIVELOG' 'CONTROLFILE'
      do
      sqlplus -S / as sysdba <<EOF >> $backupfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select * 
        from 
             (select session_key,
                    input_type,
                    status,
                    to_char(start_time, 'mm/dd/yy hh24:mi') start_time,
                    to_char(end_time, 'mm/dd/yy hh24:mi') end_time,
                    round(elapsed_seconds / 3600,2) hrs
               from v\$rman_backup_job_details
      		where input_type='$i'
      		  and start_time>sysdate-30
              order by start_time desc)
        where rownum<=1;
      EOF
      done
      
      if [[ `cat $backupfile | wc -l` -gt 0 ]];then
      count=`cat $backupfile | grep -Ewi "FAILED|WARNING|ERRORS" | wc -l`
      sed '1i\SESSION_KEY INPUT_TYPE       STATUS               START_TIME     END_TIME              HRS' $backupfile >>$fina_backupfile
      if [[ $count -gt 0 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe backup of DB is failed at $dt."
         echo ""
         echo "The following is the failed backup detail."
         cat $fina_backupfile | grep -Ewi "FAILED|WARNING|ERRORS|STATUS"
      else
         output=0
         echo -e "The backup of DB is \033[32mnormal\033[0m at $dt."  
      fi
      else
         echo "It doesn't have any backup of DB,it's not what oracle suggests."
      fi
      exit 0
      
      14、检查ADG同步情况
      [oracle@leo-oel151 scripts]$ vi chk_adg.sh
      #!/bin/bash
      source /home/oracle/.bash_profile
      MT_HOME="/home/oracle/monitor"
      dt=`date +%Y%m%d_%H:%M:%S`
      apply_file="$MT_HOME/tmp/apply_file.txt"
      db_role="$MT_HOME/tmp/db_role.txt"
      mrpfile="$MT_HOME/tmp/mrpfile.txt"
      mrp_status="$MT_HOME/tmp/mrp_status.txt"
      fina_mrp_status="$MT_HOME/tmp/fina_mrp_status.txt"
      jud_file="$MT_HOME/tmp/jud_file.txt"
      test -d /home/oracle/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      
      sqlplus -S / as sysdba <<EOF > $jud_file
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select open_mode from v\$database;
      EOF
      
      jud_act=`cat $jud_file | grep -i "read" | wc -l`
      if [[ $jud_act -eq 1 ]];then
      sqlplus -S / as sysdba <<EOF > $db_role
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select database_role from v\$database;
      EOF
      
      jud_db_role=`cat $db_role | grep "PHYSICAL STANDBY" | wc -l`
      if [[ ${jud_db_role} -eq 1 ]];then
      sqlplus -S / as sysdba <<EOF > $mrpfile
      set linesize 190 pagesize 0;
      set feedback off;
      set verify off;
      select process,status 
        from v\$managed_standby;
      EOF
      
      mrp_num=`cat $mrpfile | grep MRP0 | wc -l`
      cat $mrpfile | grep MRP0 >$mrp_status
      sed '1i\PROCESS   STATUS' $mrp_status >$fina_mrp_status
        if [[ $mrp_num -eq 1 ]];then
          abno_mrp_pro=`cat $mrpfile | grep MRP0 | grep -iwE "WAIT_FOR_LOG|WAIT_FOR_GAP" | wc -l | sed -e 's/\r//g'`
           if [[ $abno_mrp_pro -eq 1 ]];then
      	    output=1
      		echo -e "\033[31mAttention,please!\033[0mSomething wrong with the MRP process,please check it." 
      		echo ""
      		echo "The following is the detail."
      		cat $fina_mrp_status
      		exit 1
      	 else 	
           sqlplus -S / as sysdba <<EOF > $apply_file
           set linesize 190 pagesize 0;
           set feedback off;
           set verify off;
           select name||'='||value 
             from v\$dataguard_stats 
            where (substr(value,8,2)>1 or substr(value,5,2)>1)
              and name like '%lag';
      exit;
      EOF
      	 fi
        else
          output=1
          echo -e "\033[31mAttention,please!\033[0mThe ADG doesn't start MRP process."
          exit 1	
        fi
      
      delay_time=`cat $apply_file | grep -i apply | awk -F '=' '{print $2}' | awk '{print $2}'`
      delay_trans=`cat $apply_file | grep -i transport | awk -F '=' '{print $2}' | awk '{print $2}'`
      count01=`cat $apply_file | grep -i apply | awk -F '=' '{print $2}' | wc -l`
      count02=`cat $apply_file | grep -i transport | awk -F '=' '{print $2}' | wc -l`
      
      if [[ $count01 -eq 1 ]] || [[ $count02 -eq 1 ]];then
         output=1
         echo -e "\033[31mAttention,please!\033[0mThe status of ADG is abnormal at $dt,and archive files apply at physical standby delayed for \033[31m$delay_time\033[0m,archive files transport from primary delayed for \033[31m$delay_trans\033[0m."  
         exit 1
      else
         output=0
         echo -e "The status of ADG is \033[32mnormal\033[0m at $dt."   
      fi
      
      else
        echo "This isn't slave node,please run this script on slave node!"
        exit 1
      fi
      
      else
         output=1
         echo "Something wrong with the DB,please check it ASAP."
      fi
      exit 0
      
      15、前一天alert日志
      [grid@hisdb1 scripts]# vi chk_gi_alert.sh
      #!/bin/bash
      MT_HOME=/home/grid/monitor
      hname=`hostname`
      ipaddr=`cat /etc/hosts | grep -w "$hname" | grep -Ev "priv|vip" | awk '{print $1}'`
      
      last_day="`date -d -1day +%Y-%m-%d`"
      test -d /home/grid/monitor/log || mkdir -p /home/grid/monitor/log
      test -d /home/grid/monitor/tmp || mkdir -p /home/grid/monitor/tmp
      
      ### check current day ASM alert log ###
      asm_curdy_alert_log="$MT_HOME/log/${ipaddr}_asm_alert_`date +%Y%m%d`.log"
      ASM_SID=`ps -ef | grep asm_pmon | grep -v grep | awk -F'_' '{print $3}'`
      source /home/grid/.bash_profile
      sqlplus -S / as sysdba <<EOF > $MT_HOME/tmp/asm_trace_dir.txt
      set linesize 190 pagesize 0;
      set feedback off;
      select VALUE from v\$diag_info where name='Diag Trace';
      EOF
      
      asm_alert_log="`cat $MT_HOME/tmp/asm_trace_dir.txt`/alert_${ASM_SID}.log"
      sed -n "/^$last_day/,/GG/"p $asm_alert_log > $asm_curdy_alert_log
      
      #SID=`echo $asm_curdy_alert_log | awk -F'/' '{print $NF}' | awk -F'_' '{print $2}'`
      echo "###################IP ADDR:$ipaddr -- SID: $ASM_SID ########################"
      err_cnt=`cat $asm_curdy_alert_log | grep -Ei "ora-|error|warn|System state dump|Deadlock" | wc -l`
      
      if [ $err_cnt -eq 0 ];then
         output=0
         echo "There isn't error message in asm alertfile!"
      else
         output=1
         echo -e "\033[31mAttention,please!\033[0mThere are some error messages in asm alertfile!"
         echo ""
         cat $asm_curdy_alert_log | grep -Ei "ora-|error|warn|System state dump|Deadlock" -C1
      fi
      
      #test -f $asm_curdy_alert_log && rm -f $asm_curdy_alert_log
      exit 0
      
      [oracle@hisdb1 scripts]# vi chk_db_alert.sh
      #!/bin/bash
      MT_HOME=/home/oracle/monitor
      hname=`hostname`
      ipaddr=`cat /etc/hosts | grep -w "$hname" | grep -Ev "priv|vip" | awk '{print $1}'`
      
      last_day="`date -d -1day +%Y-%m-%d`"
      test -d /home/oracle/monitor/log || mkdir -p /home/oracle/monitor/log
      test -d /home/oralce/monitor/tmp || mkdir -p /home/oracle/monitor/tmp
      
      ### check current day DB alert log ###
      jud_act=`ps -ef | grep ora_pmon | grep -v grep | awk -F'_' '{print $3}' | wc -l`
      if [[ $jud_act -gt 0 ]];then
      for DB_SID in $(ps -ef | grep ora_pmon | grep -v grep | awk -F'_' '{print $3}')
      do
      db_curdy_alert_log="$MT_HOME/log/${ipaddr}_${DB_SID}_alert_`date +%Y%m%d`.log"
      source /home/oracle/.bash_profile
      sqlplus -S / as sysdba <<EOF > $MT_HOME/tmp/db_trace_dir.txt
      set linesize 190 pagesize 0;
      set feedback off;
      select VALUE from v\$diag_info where name='Diag Trace';
      EOF
      
      db_alert_log="`cat $MT_HOME/tmp/db_trace_dir.txt`/alert_${DB_SID}.log"
      
      sed -n "/^$last_day/,/GG/"p $db_alert_log > $db_curdy_alert_log
      
      echo "###################IP ADDR:$ipaddr -- SID: $DB_SID ########################"
      err_cnt=`cat $db_curdy_alert_log | grep -Ei "ora-|error|warn|System state dump|Deadlock" | wc -l`
      
      if [ $err_cnt -eq 0 ];then
         output=0
         echo "There isn't error message in db alertfile!"
      else
         output=1
         echo -e "\033[31mAttention,please!\033[0mThere are some error messages in DB alertfile!"
         cat $db_curdy_alert_log | grep -Ei "ora-|error|warn|System state dump|Deadlock" -C1
      fi
      
      #test -f $db_curdy_alert_log && rm -f $db_curdy_alert_log
      done
      
      else
         output=1
         echo "Something wrong with the DB,please check it ASAP."
      fi
      exit 0
      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/u_12991611/9921591,作者:Liujun_Deng,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:【技巧模版】数组原地修改的专栏训练(java版本含注释)

      下一篇:Eclipse里使用Servlet实现简单的登录功能

      相关文章

      2025-05-14 09:51:15

      java怎么对线程池做监控

      对Java线程池进行监控是确保系统性能和稳定性的重要部分。监控线程池可以帮助我们了解线程池的状态,如当前活跃线程数、任务队列长度、已完成任务数等。

      2025-05-14 09:51:15
      Java , 方法 , 监控 , 示例 , 线程 , 队列
      2025-05-13 09:49:27

      shell基础_开发规范解读

      shell基础_开发规范解读

      2025-05-13 09:49:27
      学习 , 小结 , 开发 , 脚本 , 规范 , 解析
      2025-05-13 09:49:19

      内置变量_其他相关

      内置变量_其他相关

      2025-05-13 09:49:19
      参数 , 基础知识 , 实践 , 小结 , 脚本 , 进程
      2025-05-13 09:49:19

      内置变量_脚本相关

      内置变量_脚本相关

      2025-05-13 09:49:19
      shell , 实践 , 当前 , 执行 , 脚本 , 获取
      2025-05-13 09:49:12

      JS学习(3)(JS代码——三种书写位置的写法与总结)

      JS代码的3种书写位置,分别为:行内、内嵌和外部。

      2025-05-13 09:49:12
      HTML , script , 代码 , 标签 , 脚本
      2025-05-12 08:40:18

      C#目录文件监控

      C#目录文件监控

      2025-05-12 08:40:18
      控制台 , 源码 , 监控 , 目录 , 程序
      2025-05-09 08:51:09

      【Linux 从基础到进阶】系统资源监控与报警

      【Linux 从基础到进阶】系统资源监控与报警

      2025-05-09 08:51:09
      CPU , 工具 , 监控
      2025-05-08 09:03:07

      【Linux】【shell】ssh互信脚本,亲测很实用

      在Linux服务器的日常管理中,SSH互信是一个非常重要的功能,它允许我们无需输入密码即可在服务器之间进行安全访问。但是,手动设置SSH互信可能会非常繁琐,特别是当我们需要在多台服务器之间建立互信关系时。

      2025-05-08 09:03:07
      ssh , SSH , 密码 , 脚本
      2025-05-07 09:09:26

      【Linux 从基础到进阶】灾备系统的监控与管理

      灾备(Disaster Recovery,DR)系统是指在发生自然灾害、系统故障或其他突发事件时,用于恢复业务操作的解决方案。其主要目标是最大限度地减少系统停机时间和数据丢失。

      2025-05-07 09:09:26
      工具 , 监控 , 系统 , 解决方案
      2025-05-06 09:19:51

      【Linux 从基础到进阶】CPU性能调优与监控

      在计算机系统中,CPU是核心组件之一,其性能直接影响系统的整体表现和响应速度。无论是在企业服务器环境、虚拟化环境,还是大数据计算场景,优化和监控CPU性能都至关重要。通过合理的调优策略和监控工具,管理员可以提升系统效率,减少资源浪费,确保业务系统的稳定运行。

      2025-05-06 09:19:51
      CPU , 性能 , 监控 , 调优 , 调度
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5250068

      查看更多

      最新文章

      【Linux】【shell】ssh互信脚本,亲测很实用

      2025-05-08 09:03:07

      【Linux 从基础到进阶】CPU性能调优与监控

      2025-05-06 09:19:51

      【Linux 从基础到进阶】 Shell脚本编写技巧与实战

      2025-05-06 08:30:38

      通过java调用shell脚本实现服务的重启

      2025-04-22 09:40:08

      为什么说k8s中监控更复杂了

      2025-04-16 09:26:39

      spring-boot-admin-starter-server监控springboot项目

      2025-04-11 07:16:05

      查看更多

      热门文章

      Linux 快速使用脚本判断某个安装包是否安装

      2023-05-04 09:35:15

      zabbix-nginx监控

      2023-05-04 08:59:25

      windows 脚本 编写

      2023-03-14 11:21:34

      快速入门Redis调用Lua脚本及使用场景介绍

      2023-05-23 09:45:41

      Elasticsearch集群监控

      2023-05-26 10:24:10

      Linux脚本练习之script023-提示用户输入 `yes` 或 `no`,并判断用户输入的是`yes` 还是 `no`,或是其它信息。

      2023-06-15 06:31:52

      查看更多

      热门标签

      linux java python javascript 数组 前端 docker Linux vue 函数 shell git 节点 容器 示例
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      python常用的备份脚本

      Linux脚本练习之script047-统计英语一句话中字母数不大于6的单词。

      shell脚本基础

      case

      为什么说k8s中监控更复杂了

      最佳的解决方案关于:cactiez监控linux主机时iptables阻碍了udp161端口造成无法监控解

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号