ogg監控指令碼

jelephant發表於2014-04-16
本機

/home/oracle/ogg_moni/oggchk.sh

# /bin/sh
# Setup the environment variables
# Set the public environment variable
export ORACLE_BASE=/oracle/app/oracle
export GI_HOME=/oracle/app/11.2.0/grid
export ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1
export NLS_LANG=American_America.ZHS16GBK
export TMP=/tmp
export TMPDIR=/tmp
export ORACLE_TERM=vt100
OPATCH_PLATFORM_ID=212
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$GI_HOME/bin:$PATH:/usr/ccs/bin:/usr/bin/X11:/usr/java5/bin
#
# Determine the even in the computer name
now_date=`date  +"%y-%m-%d %T"`
host_name=`uname -n`
#prefix_host=`echo $host_name | sed 's/\(.*\)\(.\)$/\1/'`
((postfix_host=`echo $host_name | sed 's/\(.*\)\(.\)$/\2/'`))
if [ `expr $postfix_host % 2` -eq 0 ];then even=y;else even=n;fi
#
# Set up private environment variables
((i=`ps -ef|grep ora_ckpt|grep -v grep|wc -l`))
case $i in

0)

   echo "There is no database running"
   exit 0
   ;;


1)

  ((postfix_sid=`ps -ef|grep ora_ckpt|grep -v grep|awk '{print $NF}'|awk -F "_" '{print $3}'|sed 's/\(.*\)\(.\)$/\2/'`))
  if [ $postfix_sid -eq 1 ]
  then
    export ORACLE_SID=`ps -ef|grep ora_ckpt|grep -v grep|awk '{print $NF}'|awk -F "_" '{print $3}'`
    export OGG_HOME=$ORACLE_BASE/ogg
    export LIBPATH=$OGG_HOME:$ORACLE_HOME/lib
  else
    echo "GoldenGate under normal circumstances is not running on this computer nodes"
    exit 0
  fi
  ;;

2)

  if [ $even = "n" ]
  then
    export ORACLE_SID=`ps -ef|grep ora_ckpt|grep -v grep|awk -F "_" '{print $3}'|sort|awk 'NR==1 {print}'`
    export OGG_HOME=$ORACLE_BASE/ogg
    export LIBPATH=$OGG_HOME:$ORACLE_HOME/lib
  else    
    if [ $even = "y" ]
    then
      export ORACLE_SID=`ps -ef|grep ora_ckpt|grep -v grep|awk -F "_" '{print $3}'|sort|awk 'NR==2 {print}'`
      export OGG_HOME=$ORACLE_BASE/ogg2
      export LIBPATH=$OGG_HOME:$ORACLE_HOME/lib
    else
      echo "Application error"
      exit 0
    fi
  fi   
  ;;

*)

  echo "Application error"
  exit 0
  ;;

esac

#echo $ORACLE_BASE
#echo $ORACLE_HOME
#echo $ORACLE_SID
#echo $OGG_HOME
#echo $LIBPATH

cd $OGG_HOME
$OGG_HOME/ggsci </home/oracle/ogg_moni/ogginfo.txt
info all >>/home/oracle/ogg_moni/ogginfo.txt
exit
EOF
cd /home/oracle

# The working state of the GoldenGate
sed '/^$/d' /home/oracle/ogg_moni/ogginfo.txt >/home/oracle/ogg_moni/tempinfo.txt
num_temp=`cat -n /home/oracle/ogg_moni/tempinfo.txt|grep MANAGER|awk '{print $1}'`
let num_start=num_temp+1
num_end=`cat /home/oracle/ogg_moni/tempinfo.txt|wc -l`
let num_end=num_end-0
awk 'NR=='$num_start', NR=='$num_end' {print}'  /home/oracle/ogg_moni/tempinfo.txt>/home/oracle/ogg_moni/temp_ogg.txt
#
# Determine the working state of the GoldenGate

run_all=`cat /home/oracle/ogg_moni/tempinfo.txt|grep MANAGER| awk  '{print $0}'`  
run_name=`cat /home/oracle/ogg_moni/tempinfo.txt|grep MANAGER|awk  '{print $3}'`  
run_staus=`cat /home/oracle/ogg_moni/tempinfo.txt|grep MANAGER|awk '{print $2}'`
if [ $run_staus = "RUNNING" ]
then
   echo "$now_date  $host_name  $run_all normal-work"
else
   echo "$now_date  $host_name  $run_all NOT-WORK"
fi

num_end=`cat /home/oracle/ogg_moni/temp_ogg.txt|wc -l`
i=1
until [[ $i -gt $num_end ]]; do
run_all=`awk 'NR=='$i' {print $0}'  /home/oracle/ogg_moni/temp_ogg.txt`
run_name=`awk 'NR=='$i' {print $3}'  /home/oracle/ogg_moni/temp_ogg.txt`
run_staus=`awk 'NR=='$i' {print $2}'  /home/oracle/ogg_moni/temp_ogg.txt`
if [ $run_staus = "RUNNING" ]
then
   ((run_check=`awk 'NR=='$i' {print $4}'  /home/oracle/ogg_moni/temp_ogg.txt|sed 's/://g'`))
   if [ $run_check -gt 1500 ]
   then
     echo "$now_date  $host_name  $run_all normal-work ckpt-abnormal"
   else
     echo "$now_date  $host_name  $run_all normal-work ckpt-normal"
   fi
else
   echo "$now_date  $host_name  $run_all NOT WORK"
fi

let i=i+1
# To prevent the infinite loop
if [ $i -eq 50 ]
then
break
fi

done


多個機器監控

/home/oracle/ogg_moni/oggchk_all.sh

ssh 10.161.2.86   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.41   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.42   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.46   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.47   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.51   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.52   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.56   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.57   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.61   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.62   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.66   /home/oracle/ogg_moni/oggchk.sh
ssh 10.161.2.67   /home/oracle/ogg_moni/oggchk.sh



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29337971/viewspace-1142979/,如需轉載,請註明出處,否則將追究法律責任。

相關文章