{"id":4717,"date":"2023-02-16T14:19:05","date_gmt":"2023-02-16T05:19:05","guid":{"rendered":"http:\/\/haisins.synology.me\/wordpress\/?p=4717"},"modified":"2023-02-16T14:19:05","modified_gmt":"2023-02-16T05:19:05","slug":"asm-check-crs-status-script","status":"publish","type":"post","link":"http:\/\/haisins.synology.me\/wordpress\/?p=4717","title":{"rendered":"ASM \u2013 CHECK CRS STATUS SCRIPT"},"content":{"rendered":"<h1 class=\"entry-title\">ASM \u2013 CHECK CRS STATUS SCRIPT<\/h1>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>#!\/usr\/bin\/ksh<br \/>\n#This script gives crs status<br \/>\nif [[ `uname -s` = \u201cSunOS\u201d ]] ; then<br \/>\nAWK=\/usr\/bin\/nawk<br \/>\nelse<br \/>\nAWK=\/usr\/bin\/awk<br \/>\nfi<\/p>\n<p>function print_usage {<br \/>\necho \u201d \u201d<br \/>\necho \u201cUsage: crsstat [-h] [-c] [search term]\u201d<br \/>\necho \u201d \u201d<br \/>\necho \u201d -h =&gt; print this message\u201d<br \/>\necho \u201d -c =&gt; output the resources by cluster or local\u201d<br \/>\necho \u201d \u201d<br \/>\necho \u201d Examples:\u201d<br \/>\necho \u201d crsstat # show all resources\u201d<br \/>\necho \u201d crsstat listener # only show listener resources\u201d<br \/>\necho \u201d crsstat database # only show database resources\u201d<br \/>\necho \u201d crsstat -c listener # only show database resources sorted by cluster\/local\u201d<br \/>\necho \u201d \u201d<br \/>\necho \u201d Output Contains the following fields:\u201d<br \/>\necho \u201d Resource Name\u201d<br \/>\necho \u201d Resource Type, which includes an identifier C-Cluster and L-Local\u201d<br \/>\necho \u201d Target State\u201d<br \/>\necho \u201d Current State\u201d<br \/>\necho \u201d Current Node (11gR2: or the last node in paraenthesis if the resource is Offline)\u201d<br \/>\necho \u201d Failure Count (11gR2 only)\u201d<br \/>\necho \u201d Restart Count (11gR2 only)\u201d<br \/>\necho \u201d State Details (11gR2 only)\u201d<br \/>\nexit 101<br \/>\n} # print_usage<\/p>\n<p>function get_cmdline_options {<br \/>\nwhile getopts \u201c:chv\u201d opt; do<br \/>\ncase ${opt} in<br \/>\nc ) sort_cluster_local=\u201dtrue\u201d<br \/>\n;;<br \/>\nh ) print_usage<br \/>\nexit 10<br \/>\n;;<br \/>\nv ) echo \u201cVersion: $VERSION\u201d<br \/>\nexit 100<br \/>\n;;<br \/>\n* ) echo \u201cError: Invalid option specified.\u201d<br \/>\nprint_usage<br \/>\nexit 10<br \/>\n;;<br \/>\nesac<br \/>\ndone<br \/>\nshift $(($OPTIND -1))<br \/>\n} # get_cmdline_options<\/p>\n<p>get_cmdline_options $@<br \/>\nenv_file=$(dirname $0)\/crsstat.env<br \/>\nif [[ -e ${env_file} ]] ; then<br \/>\n. ${env_file}<br \/>\nelse<br \/>\nCRSCMD=\u201dquery crs softwareversion\u201d<br \/>\nHASCMD=\u201dquery has softwareversion\u201d<br \/>\n# Try to auto-determine CRS or HAS home &amp; version<br \/>\nCSSD_DIR=`dirname $( ps -eo args | grep ocssd.bin | grep -v grep | ${AWK} \u2018{print $1}\u2019)`<br \/>\nif [[ ! -z ${CSSD_DIR} || ${CSSD_DIR} == \u201c.\u201d ]] ; then<br \/>\nCSSD_DIR=$(dirname $( ps -eo args | grep hasd.bin | grep -v grep | ${AWK} \u2018{print $1}\u2019))<br \/>\nfi<br \/>\nif [[ ! -z ${CSSD_DIR} ]] ; then<br \/>\nGRID_HOME=`echo $CSSD_DIR|${AWK} \u2018{print substr( $1, 1, length( $1)-4)}\u2019`<br \/>\nretval=`${CSSD_DIR}\/crsctl ${CRSCMD}`<br \/>\nrc=$?<br \/>\nif (( ${rc} != 0 )) ; then<br \/>\nretval=`${CSSD_DIR}\/crsctl ${HASCMD}`<br \/>\nrc=$?<br \/>\nif (( ${rc} != 0 )); then<br \/>\necho \u201cThe CRS or HAS version could not be determined.\u201d<br \/>\necho \u201cCommands to query for either failed.\u201d<br \/>\necho \u201cExiting\u2026.\u201d<br \/>\nexit 2<br \/>\nfi<br \/>\nfi<br \/>\nGRID_VER=`echo \u201c${retval}\u201d | ${AWK} \u2018{print substr( $NF, 2, 4)}\u2019`<br \/>\nif [[ ! -z ${GRID_HOME} || ! -z ${GRID_VER} ]] ; then<br \/>\necho \u201cGRID_HOME=${GRID_HOME}\u201d &gt; ${env_file}<br \/>\necho \u201cGRID_VER=${GRID_VER}\u201d &gt;&gt; ${env_file}<br \/>\nfi<br \/>\nelse<br \/>\necho \u201cThe CRS or HAS home directory could not be determined.\u201d<br \/>\necho \u201cIf CRS or HAS are down, this could be the cause of the error.\u201d<br \/>\necho \u201cExiting\u2026.\u201d<br \/>\nexit 1<br \/>\nfi<br \/>\nfi<\/p>\n<p>if [[ -z ${GRID_HOME} || -z ${GRID_VER} ]] ; then<br \/>\necho \u201cThe configuration of your GRID Infrastructure could not be determined.\u201d<br \/>\necho \u201cExiting\u2026.\u201d<br \/>\nexit 5<br \/>\nfi<\/p>\n<p>format_crs_status_resource=\u2019<br \/>\nBEGIN {<br \/>\nFS=\u201d=\u201d;<br \/>\nittype=empty<br \/>\nlastnode=\u201d\u201d<br \/>\n}<br \/>\n{<br \/>\nif ( $1 == \u201cNAME\u201d) {<br \/>\ntname=$2<br \/>\ntx=split( $2, tsplit, \u201c.\u201d)<br \/>\ntabrev=tsplit[tx]<br \/>\nttype=\u201dunknown\u201d<br \/>\nif ( tabrev == \u201casm\u201d )<br \/>\nttype=\u201dASM\u201d<br \/>\nif ( tabrev == \u201clsnr\u201d )<br \/>\nttype=\u201dListener\u201d<br \/>\nif ( tabrev == \u201cdb\u201d )<br \/>\nttype=\u201dDatabase\u201d<br \/>\nif ( tabrev == \u201cinst\u201d )<br \/>\nttype=\u201dInstance\u201d<br \/>\nif ( tabrev == \u201cvip\u201d )<br \/>\nttype=\u201dVirtual IP\u201d<br \/>\nif ( tabrev == \u201cons\u201d )<br \/>\nttype=\u201dOra Notif Svc\u201d<br \/>\nif ( tabrev == \u201ccs\u201d )<br \/>\nttype=\u201dService\u201d<br \/>\nif ( tabrev == \u201csrv\u201d )<br \/>\nttype=\u201dService\u201d<br \/>\n}<br \/>\nif ( $1 == \u201cTYPE\u201d) {<br \/>\nottype=$2<br \/>\nif (ottype == \u201capplication\u201d) {<br \/>\nottype=ttype<br \/>\nittype=empty<br \/>\n}<br \/>\nelse {<br \/>\ntx=split( $2, tsplit, \u201c.\u201d)<br \/>\nittype=tsplit[2]<br \/>\nif ( ittype == \u201casm\u201d )<br \/>\nottype=\u201dASM\u201d<br \/>\nelse if ( ittype == \u201cgsd\u201d )<br \/>\nottype=\u201dGbl Svc Daemon\u201d<br \/>\nelse if ( ittype == \u201clistener\u201d )<br \/>\nottype=\u201dListener\u201d<br \/>\nelse if ( ittype == \u201cscan_listener\u201d )<br \/>\nottype=\u201dSCAN Listener\u201d<br \/>\nelse if ( ittype == \u201cscan_vip\u201d )<br \/>\nottype=\u201dSCAN VIP\u201d<br \/>\nelse if ( ittype == \u201coc4j\u201d )<br \/>\nottype=\u201dOC4J\u201d<br \/>\nelse if ( ittype == \u201ceons\u201d )<br \/>\nottype=\u201deons\u201d<br \/>\nelse if ( ittype == \u201cons\u201d )<br \/>\nottype=\u201dOra Notif Svc\u201d<br \/>\nelse if ( ittype == \u201cnetwork\u201d )<br \/>\nottype=\u201dNetwork (VIP)\u201d<br \/>\nelse if ( ittype == \u201ccluster_vip_net1\u2033 )<br \/>\nottype=\u201dCluster VIP\u201d<br \/>\nelse ottype=ittype<br \/>\n}<br \/>\n}<br \/>\nif ( $1 == \u201cCARDINALITY_ID\u201d ) {<br \/>\nif ( $2 == \u201cONLINE\u201d || $2 == \u201cOFFLINE\u201d ) {<br \/>\nrtype=\u201dL\u201d<br \/>\n}<br \/>\nelse {<br \/>\nrtype=\u201dC\u201d<br \/>\n}<br \/>\n}<br \/>\nif ( $1 == \u201cLAST_SERVER\u201d) {<br \/>\nlastnode=\u201d(\u201c$2\u2033)\u201d<br \/>\n}<br \/>\nif ( $1 == \u201cRESTART_COUNT\u201d) {<br \/>\ntrc=$2<br \/>\n}<br \/>\nif ( $1 == \u201cFAILURE_COUNT\u201d) {<br \/>\ntfc=$2<br \/>\n}<br \/>\nif ( $1 == \u201cTARGET\u201d) {<br \/>\nttarget=$2<br \/>\ntx=split( $2, targetsplit, \u201c,\u201d)<br \/>\n}<br \/>\nif ( $1 == \u201cSTATE\u201d) {<br \/>\nif ( ittype == \u201casm\u201d || ittype == \u201cons\u201d || ittype == \u201ceons\u201d || ittype == \u201cnetwork\u201d || ittype == \u201clistener\u201d ) {<br \/>\nstx=split( $2, statesplit, \u201c,\u201d)<br \/>\n}<br \/>\nelse {<br \/>\ntx=split( $2, tsplit, \u201d \u201c)<br \/>\ntstate=tsplit[1]<br \/>\ntnode=tsplit[3]<br \/>\n}<br \/>\n}<br \/>\nif ( $1 == \u201cSTATE_DETAILS\u201d) {<br \/>\ntdetail=$2<br \/>\nif ( ittype == \u201casm\u201d || ittype == \u201cons\u201d || ittype == \u201ceons\u201d || ittype == \u201cnetwork\u201d || ittype == \u201clistener\u201d ) {<br \/>\nfor (i in statesplit) {<br \/>\ntx=split( statesplit[i], tsplit, \u201d \u201c)<br \/>\ntstate=tsplit[1]<br \/>\ntnode=tsplit[3]<br \/>\nttarget=targetsplit[i]<br \/>\ngsub(\/ *\/,\u201d\u201d,ttarget)<br \/>\ngsub(\/ *\/,\u201d\u201d,tstate)<br \/>\nif ( tnode == \u201c\u201d )<br \/>\ntnode=lastnode<br \/>\nif ( parm_rtype == \u201cA\u201d || ( parm_rtype == rtype ) ) {<br \/>\nif ( ttarget == \u201cONLINE\u201d &amp;&amp; tstate != \u201cONLINE\u201d )<br \/>\nprintf( \u201c[0;31;40m%-40s %-14s %1s %-10s %-12s %-15s %2s %2s %s[0m\\n\u201d, tname, ottype, rtype, ttarget, tstate, tnode, tfc, trc, tdetail)<br \/>\nelse<br \/>\nprintf( \u201c[0;37;40m%-40s %-14s %1s %-10s %-12s %-15s %2s %2s %s[0m\\n\u201d, tname, ottype, rtype, ttarget, tstate, tnode, tfc, trc, tdetail)<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nelse {<br \/>\nif ( tnode == \u201c\u201d )<br \/>\ntnode=lastnode<br \/>\nif ( parm_rtype == \u201cA\u201d || ( parm_rtype == rtype ) ) {<br \/>\nif ( ttarget == \u201cONLINE\u201d &amp;&amp; tstate != \u201cONLINE\u201d )<br \/>\nprintf( \u201c[0;31;40m%-40s %-14s %1s %-10s %-12s %-15s %2s %2s %s[0m\\n\u201d, tname, ottype, rtype, ttarget, tstate, tnode, tfc, trc, tdetail)<br \/>\nelse<br \/>\nprintf( \u201c[0;37;40m%-40s %-14s %1s %-10s %-12s %-15s %2s %2s %s[0m\\n\u201d, tname, ottype, rtype, ttarget, tstate, tnode, tfc, trc, tdetail)<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}\u2019<br \/>\n# End of variable: format_crs_status_resource<\/p>\n<p>format_crs_stat=\u2019<br \/>\n{<br \/>\nif ($1 == \u201cNAME\u201d) {<br \/>\ntname=$2<br \/>\n}<br \/>\nif ($1 == \u201cTYPE\u201d) {<br \/>\nttype=$2<br \/>\n}<br \/>\nif ($1 == \u201cTARGET\u201d) {<br \/>\nttarget=$2<br \/>\n}<br \/>\nif ($1 == \u201cSTATE\u201d) {<br \/>\nsplit( $2, tsplit, \u201d \u201c)<br \/>\ntstate=tsplit[1]<br \/>\ntnode=tsplit[3]<br \/>\nif ( ttarget == \u201cONLINE\u201d &amp;&amp; tstate != \u201cONLINE\u201d )<br \/>\nprintf( \u201c[0;31;40m%-40s %-14s %-10s %-12s %-15s[0m\\n\u201d, tname, ttype, ttarget, tstate, tnode)<br \/>\nelse<br \/>\nprintf( \u201c[0;37;40m%-40s %-14s %-10s %-12s %-15s[0m\\n\u201d, tname, ttype, ttarget, tstate, tnode)<br \/>\n}<br \/>\n}\u2019<br \/>\n# End of variable: format_crs_stat<\/p>\n<p>printf \u201c[0;40;37m\\n\\n%-40s %-16s %-10s %-12s %-15s %-2s %-2s %s[0m\\n\u201d \u201cResource Name\u201d \u201cResource Type\u201d \u201cTarget\u201d \u201cState\u201d \u201cNode\u201d \u201cFC\u201d \u201cRC\u201d \u201cState Details\u201d<br \/>\nprintf \u201c[0;40;37m%-40s %-16s %-10s %-12s %-15s %-2s %-2s %s[0m\\n\u201d \u201c\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-\u201d \u201c\u2014\u2014\u2014\u2014\u2014-\u201d \u201c\u2014\u2014\u2014-\u201d \u201c\u2014\u2014\u2014\u2014\u201d \u201c\u2014\u2014\u2014\u2014\u2014\u201d \u201c\u2013\u201d \u201c\u2013\u201d \u201c\u2014\u2014\u2014\u2014\u2014\u201d<\/p>\n<p>if [[ ${GRID_VER} == \u201c11.2\u201d ]] ; then<br \/>\nformat_output=${format_crs_status_resource}<br \/>\nif [[ \u201c$1\u201d != \u201c-c\u201d ]] ; then<br \/>\nsearchterm=$1<br \/>\nelif [[ ! -z \u201c$2\u2033 ]] ; then<br \/>\nsearchterm=$2<br \/>\nfi<br \/>\nif [[ ! -z ${sort_cluster_local} ]] ; then<br \/>\nsort_cluster_local=\u201dlocal\u201d<br \/>\nprintf \u201c[0;40;37mLocal Resources[0m\\n\u201d<br \/>\nprintf \u201c[0;40;37m\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013\\n\u201d<br \/>\nif [[ -z ${searchterm} ]] ; then<br \/>\n${GRID_HOME}\/bin\/crsctl status resource -v | ${AWK} -v \u201cparm_rtype=L\u201d \u201c${format_output}\u201d<br \/>\nelse<br \/>\n${GRID_HOME}\/bin\/crsctl status resource -v | ${AWK} -v \u201cparm_rtype=L\u201d \u201c${format_output}\u201d | grep -i \u201c${searchterm}\u201d<br \/>\nfi<br \/>\nsort_cluster_local=\u201dcluster\u201d<br \/>\nprintf \u201c[0;40;37m\\nCluster Resources[0m\\n\u201d<br \/>\nprintf \u201c[0;40;37m\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013[0m\\n\u201d<br \/>\nif [[ -z ${searchterm} ]] ; then<br \/>\n${GRID_HOME}\/bin\/crsctl status resource -v | ${AWK} -v \u201cparm_rtype=C\u201d \u201c${format_output}\u201d<br \/>\nelse<br \/>\n${GRID_HOME}\/bin\/crsctl status resource -v | ${AWK} -v \u201cparm_rtype=C\u201d \u201c${format_output}\u201d | grep -i \u201c${searchterm}\u201d<br \/>\nfi<br \/>\nelse<br \/>\nif [[ -z ${searchterm} ]] ; then<br \/>\n${GRID_HOME}\/bin\/crsctl status resource -v | ${AWK} -v \u201cparm_rtype=A\u201d \u201c${format_output}\u201d<br \/>\nelse<br \/>\n${GRID_HOME}\/bin\/crsctl status resource -v | ${AWK} -v \u201cparm_rtype=A\u201d \u201c${format_output}\u201d | grep -i \u201c${searchterm}\u201d<br \/>\nfi<br \/>\nfi<br \/>\nelse<br \/>\nif [[ -e ${GRID_HOME}\/bin\/crs_stat ]] ; then<br \/>\nformat_output=${format_crs_stat}<br \/>\nif [[ \u201c$1\u201d != \u201c-c\u201d ]] ; then<br \/>\nsearchterm=$1<br \/>\nelif [[ ! -z \u201c$2\u201d ]] ; then<br \/>\nsearchterm=$2<br \/>\nfi<br \/>\nif [[ -z ${searchterm} ]] ; then<br \/>\n${GRID_HOME}\/bin\/crs_stat | ${AWK} -F= \u201c${format_output}\u201d<br \/>\nelse<br \/>\n${GRID_HOME}\/bin\/crs_stat | ${AWK} -F= \u201c${format_output}\u201d | grep -i \u201c${searchterm}\u201d<br \/>\nfi<br \/>\nelse<br \/>\necho \u201ccrs_stat was not found in the ${GRID_HOME}\/bin\u201d<br \/>\nfi<br \/>\nfi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ASM \u2013 CHECK CRS STATUS SCRIPT &nbsp; &nbsp; &nbsp; #!\/usr\/bin\/ksh #This script gives crs status if [[ `uname -s` = \u201cSunOS\u201d ]] ; then AWK=\/usr\/bin\/nawk else AWK=\/usr\/bin\/awk fi function print_usage { echo \u201d \u201d echo \u201cUsage: crsstat [-h] [-c] [search term]\u201d echo \u201d \u201d echo \u201d -h =&gt; print this message\u201d echo \u201d -c =&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3402,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":""},"categories":[9],"tags":[1274,1271,1273,1272],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/haisins.synology.me\/wordpress\/wp-content\/uploads\/2018\/02\/1-know-how-1.jpg?fit=937%2C450","amp_enabled":true,"_links":{"self":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4717"}],"collection":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4717"}],"version-history":[{"count":1,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4717\/revisions"}],"predecessor-version":[{"id":4718,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4717\/revisions\/4718"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/3402"}],"wp:attachment":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4717"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}