5fc90ba44ae886876.jpg_fo742.png

#! /bin/bash
export LANG=en_US.UTF-8
RESULT=
PWD=$(locate /srvctl | grep bin |grep grid| head -n 1)
PWD=${PWD%*srvctl}
#echo $PWD
cd $PWD
SCAN_IP=$(./srvctl config scan| grep "IP:" |awk '{print $NF}'|awk -F '/' '{print $NF}')
if [[ "$SCAN_IP" == "" ]];then
   echo "[]" 
   exit 0
fi
#echo $SCAN_IP

DBNAME=$(./crs_stat -t|grep "\.db" | awk -F '.' '{print $2}')
INSTANCENAME=
INSTANCEIP=
HOSTNAME=
PORT=$(./srvctl config listener | grep TCP |awk -F ':' '{print $3}')
function getIp(){
  INSTANCEIP=`cat /etc/hosts | grep "$HOSTNAME" | grep -v "vip" | grep -v "priv" | grep -v "scan" | grep -v "#" | awk '{print $1}'`
}

nodeList=

function getResult(){
  for i in $STATES
    do
      INSTANCENAME=$(echo $i | awk -F ',' '{print $1}')
      HOSTNAME=$(echo $i | awk -F ',' '{print $2}')
      getIp
      nodeList="$nodeList,{'nodeName':'$INSTANCENAME','nodeIp':'$INSTANCEIP','port':'$PORT'}"
      #RESULT="$RESULT$INSTANCENAME|$INSTANCEIP|$PORT;"
      if [[ "$INSTANCENAME" == "" || "INSTANCEIP" == "" ]];then
           echo "[]"
           exit 0
      fi
    done
}


STATES=$(./srvctl status database -d $DBNAME | awk '{print $2","$NF" "}')
getResult
nodeList="${nodeList#*,}"
RESULT="[{'cpname':'oracle_cluster','flags':[{'cluserName':'$SCAN_IP','nodeList':[$nodeList]}]}]"
result=`echo ${RESULT//\'/\"}`
echo $result



发表回复

您的电子邮箱地址不会被公开。

Captcha Code