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
cdPWD
SCAN_IP=(./srvctl config scan| grep "IP:" |awk '{printNF}'|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 inSTATES
    do
      INSTANCENAME=(echoi | awk -F ',' '{print 1}')
      HOSTNAME=(echo i | awk -F ',' '{print2}')
      getIp
      nodeList="nodeList,{'nodeName':'INSTANCENAME','nodeIp':'INSTANCEIP','port':'PORT'}"
      #RESULT="RESULTINSTANCENAME|INSTANCEIP|PORT;"
      if [[ "INSTANCENAME" == "" || "INSTANCEIP" == "" ]];then
           echo "[]"
           exit 0
      fi
    done
}


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



发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code