Tuesday, January 7, 2025

drr_wlsAutoStart

 #!/bin/bash

#

# +=====================================================================================+

# +=====================================================================================+

# |

# | FILENAME

# |  wlsAutoStart.sh

# |

# | DESCRIPTION

# |  A fully comprehensive script for starting and stopping complete FMW environments.

# |

# | USAGE

# |  Execute using the following syntax: wlsAutoStart.sh <command> [-session]

# |

# |  Where <command> is the main $control_command argument passed to fmw_srvctl();

# |  Refer to the AutoRestart User Guide for additional details.

# | 

# |  For internal use only, the following session flags are available:

# |   -d     Specifies this session was invoked by a daemon process.

# |   -e     Specifies this session was invoked by a CA script (EM).

# |   -m     Specifies this session was invoked by a Puppet (MCollective) agent.

# |   -r     Includes remote hosts when executing session.

# |

# | Created By

# |  Seetha Ram Nanubalu

# |

# | NOTES

# |  - The scripts invoked here should only affect the Application Tier. 

# |  - Required variables are inherited via $HOME/weblogic.properties (WLS AutoRestart)

# |  - Additional Python files should be available at $SHARED_SCRIPTS/onecommand

# |  - Silent operation can be inferred, as script contains no other input prompts.

# +=====================================================================================+



# Color Palette:

txtred=$'\e[0;31m'                 # Red

txtgrn=$'\e[0;32m'                 # Green

txtylw=$'\e[0;33m'                 # Yellow


# Text Effects

txtrst=$'\e[0m'                    # Text Reset

txtbld=$'\e[1m'                    # Text Bold

txtdim=$'\e[2m'                    # Text Dim

txtunl=$'\e[4m'                    # Text Underline

txtflsh=$'\e[5m'                   # Text Blink


# Input Arguments:

control_command=$1                  # Main command argument option for fmw_srvctl()

control_session=$2                  # Specifies if invoked session is local or remote


# Other runtime-variables:

debug_message=""                    # Debug Message string to be included in phone_home()

error_count=0                       # Initializes the error counter to zero

warning_count=0                     # Initializes the warning counter to zero

start_time=$(date +%s)              # Timestamp



unset_env() # Clears all other environment variables.

{

    PATH=$(getconf "PATH"):/sbin:/usr/sbin:$PATH

    

    unset $(env | cut -d= -f1 \

        | grep -Ev 'BASH|HOME|HOSTNAME|LANG|LOGNAME|PATH|SHELL|TERM|TZ|USER') 2>/dev/null

}


#hello() # Generates welcome banner.

#{

#    echo -e "\n\n\t\t${txtrst} ************************************\n\t\t *\c "

#    echo -e "${txtbld} Running FedMCS OneCommand Script ${txtrst}\c"

#    echo -e "*\n\t\t ************************************\n"

#}


get_my_version() # Determines this script version, no matter where it is being called from.

{

    source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

    my_version=$(grep '$Header' $source_dir/${0##*/} | head -1 | awk '{print $4}')

    rel_v_date=$(grep '$Header' $source_dir/${0##*/} | head -1 | awk '{print $5}')

}


show_usage() # Prints basic help information.

{

    get_my_version

    echo -e "\n Release Version Info:\t$my_version\t$rel_v_date"

    

    echo -e "\n Usage:" 

    echo -e "\t ${0##*/} <command_option>"

    echo -e "\t Where <command_option> is a mandatory argument!"

    

    echo -e "\n Available arguments are:"

    echo -e "\t restart_AdminServer     Bounce the AdminServer on localhost"

    echo -e "\t restart_Domain          Bounce all components in the domain"

    echo -e "\t restart_ManagedServers  Bounce the Managed Servers simultaneously"

    echo -e "\t restart_NodeManager     Bounce the Node Manager(s) on localhost"

    echo -e "\t restart_OPMN            Bounce the HTTP Server on localhost"

    echo -e "\t start_AdminServer       Start the AdminServer on localhost"

    echo -e "\t start_Domain            Start all components in the domain"

    echo -e "\t start_ManagedServers    Start the Managed Servers simultaneously"

    echo -e "\t start_NodeManager       Start the Node Manager(s) on localhost"

    echo -e "\t start_OPMN              Start the HTTP Server on localhost"

    echo -e "\t status_AdminServer      Check the status of the AdminServer on localhost"

    echo -e "\t status_Domain           Check the status of all components in the domain"

    echo -e "\t status_ManagedServers   Check the status of the Managed Servers"

    echo -e "\t status_SystemComponents Check the status of the System Components"

    echo -e "\t status_NodeManager      Check the status of the Node Manager(s)"

    echo -e "\t status_OPMN             Check the status of the HTTP Server on localhost"

    echo -e "\t stop_AdminServer        Stop the AdminServer on localhost"

    echo -e "\t stop_Domain             Stop all components in the domain"

    echo -e "\t stop_ManagedServers     Stop the Managed Servers simultaneously"

    echo -e "\t stop_NodeManager        Stop the Node Manager(s) on localhost"

    echo -e "\t stop_OPMN               Stop the HTTP Server on localhost"


    echo -e "\n Other options:"

    echo -e "\t -? --help               Print this help message"

    

    echo -e "\n Example:"

    echo -e "\t ./${0##*/} restart_Domain\n"

    

    set_exit 2

}


set_logging() # Clears log file --by keeping only the 100 most recent sessions.

    log_file="$WLSAUTOSTART_LOG"

    

    if [[ $control_session == "-d" ]]; then

        session_type="daemon init.d script"

    elif [[ $control_session == "-e" ]]; then

        session_type="CA (EM) triggered event"

    elif [[ $control_session == "-m" ]]; then

        session_type="MCollective job request"

    elif [[ $control_session == "-r" ]]; then

        session_type="remote session"

    else

        session_type="local session"

    fi

    

    echo -e " - Clearing older sessions from $log_file: \t\c"

 #  echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ ! -e $log_file ]]; then

        touch $log_file >/dev/null 2>&1

        chmod 777 $log_file >/dev/null 2>&1

        if (($?)); then

    ###        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            debug_message+="[CRITICAL] $FUNCNAME(): "

            debug_message+="Unable to clear $log_file!"

            set_exit 126

        fi

    fi

    

    if [[ -w $log_file ]]; then

        while (($(grep -c "== OMCS OneCommand Session End ========" $log_file) > 99)); do

            printf "%s\n" 1d wq | ed -s $log_file

        done

       ### echo -e "\b\b\b\b\b\b\b\b\b\b\c"

# echo -e "[  OK ]"

       ### echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n========== OMCS OneCommand Session Start =========\n" >>$log_file

        echo -e "$(date) :: Running ${0##*/} on instance $instance_name" >>$log_file

        echo -e "Executing $control_command option on $f_hostname" >>$log_file

        echo -e "Release $my_version ($rel_v_date), called from: $source_dir" >>$log_file

        echo -e "This is a $session_type invoked by: $user_id\n" >>$log_file

    fi

}


set_wls_properties() # Imports $HOME/weblogic.properties file, and checks permissions.

{

    wls_profile="$HOME/weblogic.properties"

  

    if [[ -z $MW_HOME ]]; then

      MW_HOME=$ORACLE_HOME ; export MW_HOME

    fi


    if [[ -z $ASERVER_HOME ]]; then

      DOMAIN_HOME=$ASERVER_HOME ; export DOMAIN_HOME

    fi


    if [[ -z $MSERVER_HOME ]]; then

      DOMAIN_HOME_M=$MSERVER_HOME ; export DOMAIN_HOME_M

    fi


    echo -e " - Defining environmental variables: \t\t\t\c"

    #echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (hostname -f >/dev/null 2>&1); then

        s_hostname=$(hostname -s | cut -d "." -f1)

        f_hostname=$(hostname -f | cut -d " " -f1)

    elif (getent hosts $(hostname) >/dev/null 2>&1); then

        s_hostname=$(getent hosts $(hostname) | awk '{print $2}' | cut -d "." -f1)

        f_hostname=$(getent hosts $(hostname) | awk '{print $2}')

    else

        s_hostname=$(echo $HOSTNAME | cut -d "." -f1)

        f_hostname=$(echo $HOSTNAME | cut -d " " -f1)

    fi

    

    if [[ -r $wls_profile ]]; then

        source $wls_profile

        admin_port=$(echo $adminURL | awk -F ":" '{print $2}')

        instance_name=$(echo $INSTANCE | tr "[:lower:]" "[:upper:]")

        instance_type=$(echo $DOMAIN_NAME | tr "[:upper:]" "[:lower:]")

        my_scripts=$SHARED_SCRIPTS/onecommand

        if [[ $INSTANCE_OWNER != $(whoami) ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\nRunning ${0##*/} as '$(whoami)'"

            echo -e "${0##*/} must be executed as '$INSTANCE_OWNER'"

            debug_message+="[CRITICAL] $FUNCNAME(): "

            debug_message+="Permission denied!"

            set_exit 126

        else

            get_wlst_properties

        fi    

    elif [[ ! -e $wls_profile ]] \

    && [[ $control_command == *"OPMN"* \

            || $control_command == *"NodeManager"* ]]; then

        get_ohs_properties

        if [[ -n $DOMAIN_HOME ]]; then

            get_nm_properties

        fi

        INSTANCE_OWNER=$instance_owner

        SHARED_SCRIPTS=/autofs/ood_repository/healthcheck

        WLSAUTOSTART_LOG="/tmp/wlsAutoStart.log"

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\nWLS AutoRestart must be implemented first!"

        instance_name=$(df -P | awk '$NF !~ /export/ {print $NF}' | grep -v "/dev/" \

            | cut -d "/" -f2 | tr "[:lower:]" "[:upper:]" | sort | uniq -c | sort -nr \

                | head  -1 | awk '{print $2}')

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="'$HOME/weblogic.properties' file not found!"

        set_exit 126

    fi

    

    if [[ -z $ADMIN_SERVER_NAME ]]; then

        ADMIN_SERVER_NAME="AdminServer"

    fi

    

    if [[ -z $DOMAIN_HOME_M ]]; then

        DOMAIN_HOME_M=$DOMAIN_HOME

    fi

    

    if [[ -z $NMPORT_M ]]; then

        local_nmport=$NMPORT

        shared_nmport=$NMPORT

    elif [[ -n $NMPORT_M ]]; then

        local_nmport=$NMPORT_M

        shared_nmport=$NMPORT

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="NodeManager Port is not defined --invalid configuration!\n"

        set_exit 126

    fi   

    

   ## echo -e "\b\b\b\b\b\b\b\b\b\b\c"

    echo -e "[  OK ]"

}


get_ohs_properties() # For DMZ type Public-MT(s), it constructs OHS necessary variables.

{

    OPMN_HOMES=""

    DMZ_DOMAIN_HOME=""

    

    instance_name=$(df -P | awk '$NF !~ /export/ {print $NF}' | grep -v "/dev/" \

            | cut -d "/" -f2 | tr "[:lower:]" "[:upper:]" | sort | uniq -c | sort -nr \

                | head  -1 | awk '{print $2}')

    instance_dir=$(echo /$instance_name | tr "[:upper:]" "[:lower:]")

    instance_owner=$(ls -l $instance_dir | awk '{print $3}' | uniq -d)

    

    if [[ -d $instance_dir/local/config/domains/ohsdomain ]]; then

        DMZ_DOMAIN_HOME="$instance_dir/local/config/domains/ohsdomain"

        DOMAIN_HOME="$DMZ_DOMAIN_HOME"

    elif [[ -r /etc/oraInst.loc ]]; then

        inventory_loc=$(grep 'inventory_loc' /etc/oraInst.loc | awk -F "=" '{print $2}')

        if [[ -r $inventory_loc/logs ]]; then

            instance_homes=($(grep -h 'Instance Home:' \

                $inventory_loc/logs/installSummary* | awk -F ":" '{print $2}' | sort -u))

            for instance in ${instance_homes[@]}; do

                if [[ -d $instance/bin ]]; then

                    OPMN_HOMES="$OPMN_HOMES$instance:"

                fi

            done

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            debug_message+="[CRITICAL] $FUNCNAME(): "

            debug_message+="Unable to read file: '$inventory_loc/logs/installSummary*'!"

            set_exit 126

        fi   

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="Unable to determine Instance Home(s)!"

        set_exit 126

    fi    

}


get_nm_properties() # For DMZ type Public-MT(s), it constructs NM necessary variables.

{

    NMPORT=""

    WLS_HOME=""

    

    nm_properties=$(find $instance_dir/local/fmw/*/wlserver*/ \

        -name ".product.properties")

    

    if [[ -n $nm_properties ]]; then

        NMPORT=$(grep NODEMGR_PORT $nm_properties | awk -F "=" '{print $2}')

        WLS_HOME=$(grep WL_HOME $nm_properties | awk -F "=" '{print $2}')

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="Unable to read file: '$nm_properties'!"

        set_exit 126

    fi

}


create_config_files()

{


  echo -e "\r\rUser config files do not exist.  Creating now."

  echo -e "Enter weblogic password:"

  read p_password


echo "#############################################################################

#

#  CreateUserConfig.py

#

#############################################################################

import java.lang

import os

import string

import sys

protocol = \"t3://\"

username = sys.argv[1]

password = sys.argv[2]

adminURL = sys.argv[3]

domain = sys.argv[4]

URL = protocol + adminURL

adminUser = domain + \"/bin/scripts/secure/admUserConf.properties\"

adminPass = domain + \"/bin/scripts/secure/admPassKey.properties\"

redirect('/dev/null', 'false')


connect (username,password,URL)

storeUserConfig(userConfigFile=adminUser,userKeyFile=adminPass)

" > /tmp/foobar.py


  export WLST_PROPERTIES="-Dweblogic.management.confirmKeyfileCreation=true"

  $MW_HOME/oracle_common/common/bin/wlst.sh /tmp/foobar.py weblogic ${p_password} $adminURL $DOMAIN_HOME

  rm /tmp/foobar.py


}


get_wlst_properties() # Gets [ohsadmin] credentials and NodeManager listener type.  

{

    properties_file1=/home/oracle/.wlst/nm-cfg-soa_domain.props

    properties_file2=/home/oracle/.wlst/nm-key-soa_domain.props


    if [[ -f $properties_file1 && -f $properties_file2 ]]; then

        username=$properties_file1

        password=$properties_file2

    elif [[ -f $DOMAIN_HOME/nodemanager/nmUserConfig.properties ]]; then

mkdir -p $DOMAIN_HOME/bin/scripts/secure

cp $DOMAIN_HOME/nodemanager/nmUserConfig.properties $properties_file1

cp $DOMAIN_HOME/nodemanager/nmUserKey.properties $properties_file2

username=$properties_file1

        password=$properties_file2

    else

mkdir -p $DOMAIN_HOME/bin/scripts/secure

create_config_files

        username=$properties_file1

        password=$properties_file2

    fi

    

    if [[ -f $WLS_HOME/common/nodemanager/nodemanager.properties ]]; then

        nm_profile="$WLS_HOME/common/nodemanager/nodemanager.properties"

    elif [[ -f $DOMAIN_HOME/nodemanager/nodemanager.properties ]]; then

        nm_profile="$DOMAIN_HOME/nodemanager/nodemanager.properties"

        nm_profile_m="$DOMAIN_HOME_M/nodemanager/nodemanager.properties"

    elif [[ -f $NM_HOME/nodemanager.properties ]]; then

        nm_profile="$NM_HOME/nodemanager.properties"

        nm_profile_m="$NM_HOME/nodemanager.properties"

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="Properties files cannot be located!"

        set_exit 126

    fi


    secure_listener=$(grep SecureListener $nm_profile | awk -F '=' '{print $2}')


    if [[ $secure_listener == "true" ]]; then

        connect_type="ssl"

    elif [[ $secure_listener == "false" ]]; then

        connect_type="plain"

    else # Connection type could not be determined; Defaulting to SSL

        connect_type="ssl"

    fi

    

    if [[ -r $nm_profile_m && -r $nm_profile ]]; then

        local_alias=$(grep ListenAddress $nm_profile_m | awk -F "=" '{print $2}')

        shared_alias=$(grep ListenAddress $nm_profile | awk -F "=" '{print $2}')

    else

        local_alias=$(grep ListenAddress $nm_profile | awk -F "=" '{print $2}')

    fi

}


get_context() # Runs WLST Offline to understand the execution context.

{

    local my_script=$my_scripts/getContext.py

    

    temp_server_file="/tmp/onecommand/server.txt"

    temp_machine_file="/tmp/onecommand/machines.txt"

    temp_prop_file="$HOME/weblogic.properties"


####    echo -e " - Probing execution context: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ -x $MW_HOME/oracle_common/common/bin/wlst.sh ]]; then

        mkdir -p /tmp/onecommand

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

        $temp_prop_file $temp_server_file $temp_machine_file >>$log_file 2>&1

        given_machines=($(cat $temp_machine_file | awk -F ":" '{print $1}' | sort -u))

    else

##        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Invalid path found for WLS_HOME in '$wls_profile'!"

        ((error_count++))

        set_exit 1

    fi

    

   for myhost in ${given_machines[@]}; do

       if [[ $myhost =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then

           given_hosts+=($(getent hosts $myhost | awk '{print $NF}' | cut -d '.' -f 1))

       else

           given_hosts+=(${myhost%%.*})

       fi

   done

    

   if ((${#given_hosts[@]} == 0)); then

       if [[ $control_session == "-m" ]]; then

       ###     echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#      echo -e "[  OK ]"

  ####          echo -e "[${txtgrn}   OK   ${txtrst}]"

           echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

           echo -e "Skipping, no further actions required for this host." >>$log_file

           set_exit 0

       else

           echo -e "\b\b\b\b\b\b\b\b\b\b\c"

           echo -e "[${txtred} FAILED ${txtrst}]"

           echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

           echo -e "No servers discovered reading the domain!\n" >>$log_file

           ((error_count++))

           set_exit 1

       fi

   else

     ###   echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#       echo -e "[  OK ]"

     ####   echo -e "[${txtgrn}   OK   ${txtrst}]"

     echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

     echo -e "Servers discovered in the domain:" >>$log_file

     printf "%s\n" "${given_hosts[@]}" >>$log_file

      echo -e "----------------\n" >>$log_file

    fi

}


validate_hosts() #Exa IP over Infiniband aliases need to be translated (e.g. ADM@Customer)

{

    remote_aliases=()

    

    for myhost in ${remote_hosts[@]}; do

        if (host $myhost >/dev/null 2>&1); then

            remote_aliases+=($myhost)

        else

            remote_aliases+=($(echo $myhost | sed 's/\-ipoib.*//g'))

        fi

    done

}


#check_ssh() # Checks for SSH User Equivalence among all know hosts.

#{

#    remote_hosts=()

#    ssh_enabled=0

    

#    echo -e " - Checking for SSH User Equivalence: \t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

#    for myhost in ${given_hosts[@]}; do

#        server_ip=$(getent hosts $myhost | awk '{print $1}' | head -1)

#        if (($((ifconfig -a || ip addr show) 2>/dev/null | grep -c $server_ip) < 1)); then

#            remote_hosts+=($myhost)

#        fi

#    done

    

#    for myhost in ${remote_hosts[@]}; do

#        returned_host=$(ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oBatchMode=yes \

#            $myhost echo "Hello World!" 2>&1)

#        if (($?)); then

#            break

#        else

#            ((ssh_enabled++))

#        fi

#    done

    

#    validate_hosts

    

#    if ((${#remote_hosts[@]} > 0)); then

#        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

#        echo -e "Remote hosts identified:" >>$log_file 

 #       printf "%s\n" "${remote_aliases[@]}" >>$log_file

  #      echo -e "----------------" >>$log_file

  #  else

  #      echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

  #      echo -e "No Remote hosts identified" >>$log_file 

  #  fi


  #  if (($ssh_enabled != 0)) && (($ssh_enabled == ${#remote_hosts[@]})); then

  #      ssh_enabled="true"

  #      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

  #      echo -e "[${txtgrn}   OK   ${txtrst}]"

  #      echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

  #      echo -e "User Equivalence is enabled between all machines!\n" >>$log_file

  #  elif ((${#remote_hosts[@]} == 0)); then

  #      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

  #      echo -e "[${txtgrn}   OK   ${txtrst}]"

  #      echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

  #      echo -e "User Equivalence not required on single node instances\n" >>$log_file

  #  else

  #      ssh_enabled="false"

  #      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

  #      echo -e "[${txtred} FAILED ${txtrst}]"

  #      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

  #      echo -e "User Equivalence is not enabled on all machines!" >>$log_file

  #      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

  #      echo -e "Unable to control component(s) for each remote host!" >>$log_file

  #      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

  #      echo -e "Please run the genKey.sh and combineKey.sh scripts, as \c" >>$log_file

  #      echo -e "per the WLS AutoRestart - Setup Instructions!" >>$log_file

  #      ((error_count++))

  #  fi

#}


check_db() # Performs database availability check(s).

    local my_script=$my_scripts/dbCheck.sh

    

    echo -e " - Performing database availability checks: \t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    source $my_script >>$log_file 2>&1

    

    if (is_db_check >>$log_file 2>&1); then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "dbTier test passed!\n" >>$log_file

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

        ((error_count++))

        set_exit 1

    fi

}


check_ports() # Check to see if the AdminServer or NodeManager(s) are actively listening.

{

    local check_option=$1

    

    case $check_option in

        admin_server)

            if (($(netstat -an | grep $admin_port | grep -c "LISTEN") >= 1)); then

                return 0

            else

                return 1

            fi

            ;;

        local_nm)

            if (($(netstat -an | grep $local_nmport | grep -c "LISTEN") >= 1)); then

                return 0

            else

                return 1

            fi

            ;;

        shared_nm)

            if (($(netstat -an | grep $shared_nmport | grep -c "LISTEN") >= 1)); then

                return 0

            else

                return 1

            fi

            ;;   

    esac

}


check_adminserver() # Check the status of the AdminServer, if running on localhost.

{

    echo -e "   > AdminServer status \c"

    

    if (check_ports admin_server); then

        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "AdminServer is running on \c" >>$log_file

        echo -e "($s_hostname:$(echo $adminURL \

            | awk -F ":" '{print $2}'))\t\t\c" | tee -a $log_file

echo -e "[   OK   ]"

 ###WGG       echo -e "[${txtgrn}   OK   ${txtrst}]"

    else

        echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "AdminServer is not running on \c" >>$log_file

        echo -e "($s_hostname:$(echo $adminURL \

            | awk -F ":" '{print $2}'))\t\t\c" | tee -a $log_file

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        ((health_counter++))

    fi

}


check_nodemanager() # Checks the status of the Node Manager(s), including remote hosts.

{       

    local control_option=$1

    

    echo -e "   > NodeManager status \c"

    

    if (check_ports local_nm); then

        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is running on \c" >>$log_file

        echo -e "($s_hostname:$local_nmport)\t\t\c" | tee -a $log_file

echo -e "[   OK   ]"

###WG        echo -e "[${txtgrn}   OK   ${txtrst}]"

    else

        echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is not running on \c" >>$log_file

        echo -e "($s_hostname:$local_nmport)\t\t\c" | tee -a $log_file

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        ((health_counter++))

    fi 

    

    if (check_ports shared_nm) && [[ $local_nmport != $shared_nmport ]]; then

        echo -e "   > NodeManager status \c"

        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is running on \c" >>$log_file

        echo -e "($s_hostname:$shared_nmport)\t\t\c" | tee -a $log_file 

        echo -e "[${txtgrn}   OK   ${txtrst}]"

    elif ! (check_ports shared_nm) && [[ $local_nmport != $shared_nmport ]]; then

        echo -e "   > NodeManager status \c"

        echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is not running on \c" >>$log_file

        echo -e "($s_hostname:$shared_nmport)\t\t\c" | tee -a $log_file

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        ((health_counter++))

    fi 

    

    if [[ $control_option == "-r" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do  

            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}' \

                ; grep $myhost_ip $temp_machine_file | awk -F ":" '{print $2}')

            bash -c "cat </dev/null >/dev/tcp/$myhost_ip/$my_nmport" >/dev/null 2>&1

            if (($?)); then

                echo -e "   > NodeManager status \c"

                echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "(${remote_aliases[$i_name]}:$my_nmport)\t\t\c" | tee -a $log_file

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                ((health_counter++))

            else

                echo -e "   > NodeManager status \c"

                echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is running on \c" >>$log_file

                echo -e "(${remote_aliases[$i_name]}:$my_nmport)\t\t\c" | tee -a $log_file

                echo -e "[${txtgrn}   OK   ${txtrst}]"

            fi

        ((i_name++))

        done

    fi

}


check_managedservers() # Checks the status of all the Managed Servers.

{

    local my_script=$my_scripts/statusMS.py

    local my_exit_code=""

    

    echo -e "   > ManagedServer(s) status \t\t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    oIFS=$IFS

    IFS=$'\n'

    

    if (check_ports admin_server); then

        echo -e "\n\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "Retrieving state of all Managed Servers" >>$log_file

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        my_exit_code=$?

        if [[ $my_exit_code == 0 ]]; then

    ###        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[  OK  ]\n"

##WG    echo -e "[${txtgrn}   OK   ${txtrst}]\n"

            echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

            echo -e "All ManagedServers are running and in a healthy state" >>$log_file

            ms_status_messages_all=($(tac $log_file \

                | awk '/- End ManagedServer /{p=1; next} \

                    p && /- Start ManagedServer /{exit} p' \

                        | tac | sed '/AdminServer/d'))

        elif [[ $my_exit_code == 3 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "Not all ManagedServers are running or in a healthy state" >>$log_file

            ms_status_messages_all=($(tac $log_file \

                | awk '/- End ManagedServer /{p=1; next} \

                    p && /- Start ManagedServer /{exit} p' \

                        | tac | sed '/AdminServer/d'))

            ((health_counter++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]\n"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

            ((error_count++))        

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on \c" >>$log_file

        echo -e "$local_alias:$(echo $adminURL | awk -F ":" '{print $2}')" >>$log_file

    fi

    

    if ((${#ms_status_messages_error[@]} > 0)); then

        ms_status_messages=("${ms_status_messages_error[@]}")

    else

        ms_status_messages=("${ms_status_messages_all[@]}")

    fi

    

    if ((${#ms_status_messages[@]} > 0)); then

        for server_status in ${ms_status_messages[@]}; do

            echo -e "\t$server_status"

        done

        echo -e ""

    else

        echo -e "\tUnable to retrieve server state!\n"

    fi

        

    IFS=$oIFS

}


check_systemcomponents() # Checks the status of all the Managed Servers.

{

    local my_script=$my_scripts/statusSCP.py

    local my_exit_code=""

    

    echo -e "   > SystemComponent(s) status \t\t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    oIFS=$IFS

    IFS=$'\n'

    

    if (check_ports admin_server); then

        echo -e "\n\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "Retrieving state of all System Components" >>$log_file

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        my_exit_code=$?

        if [[ $my_exit_code == 0 ]]; then

###            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[  OK ]\n" 

###WG      echo -e "[${txtgrn}   OK   ${txtrst}]\n"

            echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

            echo -e "All SystemComponents are running and in a healthy state" >>$log_file

            scp_status_messages_all=($(tac $log_file \

                | awk '/- End SystemComponent /{p=1; next} \

                    p && /- Start SystemComponent /{exit} p' \

                        | tac | sed '/AdminServer/d'))

        elif [[ $my_exit_code == 1 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw}   NA   ${txtrst}]\n"

            echo -e "\n[NOTICE] $FUNCNAME(): \c" >>$log_file

            echo -e "There are no system components registered in this environment" >>$log_file

            scp_status_messages_all="There are no system components registered"

        elif [[ $my_exit_code == 3 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "Not all SystemComponents are running or in a healthy state" >>$log_file

            scp_status_messages_all=($(tac $log_file \

                | awk '/- End SystemComponent /{p=1; next} \

                    p && /- Start SystemComponent /{exit} p' \

                        | tac | sed '/AdminServer/d'))

            ((health_counter++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]\n"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

            ((error_count++))        

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on \c" >>$log_file

        echo -e "$local_alias:$(echo $adminURL | awk -F ":" '{print $2}')" >>$log_file

    fi

    

    if ((${#scp_status_messages_error[@]} > 0)); then

        scp_status_messages=("${scp_status_messages_error[@]}")

    else

        scp_status_messages=("${scp_status_messages_all[@]}")

    fi

    

    if ((${#scp_status_messages[@]} > 0)); then

        for component_status in ${scp_status_messages[@]}; do

            echo -e "\t$component_status"

        done

        echo -e ""

    else

        echo -e "\tUnable to retrieve component state!\n"

    fi

        

    IFS=$oIFS

}


##check_deployments() # Checks the status of all WebLogic deployments in this domain.

#{

#    local my_script=$my_scripts/statusAD.py

#    local my_exit_code=""

    

#    echo -e "   > Application Deployment status \t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

#    oIFS=$IFS

#    IFS=$'\n'

    

#    $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#        $username $password $adminURL >>$log_file 2>&1

#    my_exit_code=$?

#    if [[ $my_exit_code == 0 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtgrn}   OK   ${txtrst}]"

#        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#        echo -e "All deployed applications are active\n" >>$log_file

#        app_active_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -c 'STATE_ACTIVE')

#        app_inactive_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -cv 'STATE_ACTIVE')

#    elif [[ $my_exit_code == 3 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#        echo -e "Not all deployed applications are active!\n" >>$log_file

#        app_active_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -c 'STATE_ACTIVE')

#        app_inactive_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -cv 'STATE_ACTIVE')

#        app_status_messages_error=($(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | cut -f1 -d"," | sed -e 's/^[ \t]*//' \

#                        | sort -u | tac| grep -v 'STATE_ACTIVE'))

#        ((health_counter++))    

#    else

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtred} FAILED ${txtrst}]"

#        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#        ((error_count++))           

#    fi

    

#    IFS=$oIFS

    

#    if ((${#app_status_messages_error[@]} > 0)); then

#        for app_status in "${app_status_messages_error[@]:0:9}"; do

#            echo -e "\t$app_status"

#        done

#        if ((${#app_status_messages_error[@]} > 10)); then

#            echo -e "\t..."

#        fi

#        echo -e "\n\tActive Count: ${txtgrn}$app_active_status_count${txtrst}\c"

#        echo -e "\tInactive Count: ${txtred}$app_inactive_status_count${txtrst}\n"

#    elif [[ -n $app_active_status_count ]]; then

#        echo -e "\n\tActive Count: ${txtgrn}$app_active_status_count${txtrst}\c"

#        echo -e "\tInactive Count: ${txtgrn}$app_inactive_status_count${txtrst}\n"

#    fi

#}


#check_composites() # Lists all Composite Applications deployed to the SOA platform.

#{

#    local my_script=$my_scripts/statusCA.py

#    local my_exit_code=""

#    

#    SOA_ORACLE_HOME=$(grep -iv '^#' $DOMAIN_HOME/bin/setDomainEnv.sh \

#        | grep -w SOA_ORACLE_HOME= | awk -F "=" '{print $2}' \

#            | sed "s/^\([\"']\)\(.*\)\1\$/\2/g" | sort -u)

#    

#    oIFS=$IFS

#    IFS=$'\n'

#    

#    if [[ -n $SOA_ORACLE_HOME ]]; then

#        echo -e "   > SOA Composites status \t\t\t\t\c"

#        echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#            $username $password $adminURL >>$log_file 2>&1

#        my_exit_code=$?

#        if [[ $my_exit_code == 0 ]]; then

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtgrn}   OK   ${txtrst}]"

#            echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#            echo -e "All deployed composites are active\n" >>$log_file

#            comp_up_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Up Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#            comp_down_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Down Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#        elif [[ $my_exit_code == 2 ]]; then

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#            ((warning_count++))

#        elif [[ $my_exit_code == 3 ]]; then

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#            echo -e "Not all deployed composites are active!\n" >>$log_file

#            comp_up_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Up Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#            comp_down_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Down Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#            comp_status_messages_error=($(tac $log_file \

#                | awk '/- End SOA Composites Down -/{p=1; next} p \

#                    && /- Start SOA Composites Down -/{exit} p' \

#                        | cut -d ']' -f 2- | cut -f1 -d"," \

#                            | sed -e 's/^[ \t]*//' | sort -u | tac))

#            ((health_counter++))

#        else

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtred} FAILED ${txtrst}]"

#            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#            ((error_count++))

#        fi

#    fi      

    

#    IFS=$oIFS

    

#    if ((${#comp_status_messages_error[@]} > 0)); then

#        for comp_status in "${comp_status_messages_error[@]:0:9}"; do

#            echo -e "\t$comp_status"

#        done

#        if ((${#comp_status_messages_error[@]} > 10)); then

#            echo -e "\t..."

#        fi

#        echo -e "\n\tUp Count: ${txtgrn}$comp_up_sum${txtrst}\c"

#        echo -e "\t\tDown Count: ${txtred}$comp_down_sum${txtrst}\n"

#    elif [[ -n $comp_up_sum ]]; then

#        echo -e "\n\tUp Count: ${txtgrn}$comp_up_sum${txtrst}\c"

#        echo -e "\t\tDown Count: ${txtgrn}$comp_down_sum${txtrst}\n"

#    fi

#}


#check_jdbc() # Checks the status of all the JDBC data sources in this domain.

#{

#    local my_script=$my_scripts/statusJDBC.py

#    local my_exit_code=""

#    

#    echo -e "   > JDBC data sources status \t\t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#    

#    oIFS=$IFS

#    IFS=$'\n'

#    

#    echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#    echo -e "Testing JDBC data sources" >>$log_file

#    

#    $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#        $username $password $adminURL >>$log_file 2>&1

#    my_exit_code=$?

#    if [[ $my_exit_code == 0 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtgrn}   OK   ${txtrst}]"

#        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#        echo -e "All JDBC Data Sources are running\n" >>$log_file

#    elif [[ $my_exit_code == 3 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#        echo -e "Not all JDBC Data Sources are running!\n" >>$log_file

#        ds_status_messages_error=($(tac $log_file \

#            | awk '/- End Datasource List -/{p=1; next} p \

#                && /- Start Datasource List -/{exit} p' \

#                    | tac | cut -d ']' -f 2- | sort -u | grep ' => FAILED'))

#        ((health_counter++))

#    else

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtred} FAILED ${txtrst}]"

#        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file       

#        ((error_count++))

#    fi

#    

#    if ((${#ds_status_messages_error[@]} > 0)); then

#        for ds_status in ${ds_status_messages_error[@]}; do

#            echo -e "\t$ds_status" | sed -e "s/FAILED/${txtred}FAILED${txtrst}/g"

#        done

#        if ((${#ds_status_messages_error[@]} > 10)); then

#            echo -e "\t...\n"

#        fi

#        echo -e ""

#    fi

#        

#    IFS=$oIFS  

#}


#check_urls() # Verifies all URLs defined in OHS.

#{

#    local my_script=$my_scripts/urlCheck.sh

#    local my_exit_code=""

#    local url_domain_strings=()

    

#    echo -e "   > URL status (modWebLogic Locations, HTTP 200/401)\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

#    oIFS=$IFS

#    IFS=$'\n'

    

#    $my_script >>$log_file 2>&1

#    my_exit_code=$?

#    if [[ $my_exit_code == 0 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtgrn}   OK   ${txtrst}]\n"

#        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#        echo -e "urlCheck test passed!\n" >>$log_file

#        url_status_messages_all=($(tac $log_file \

#            | awk '/- End URL List -/{p=1; next} p && /- Start URL List -/{exit} p' \

#                | awk '{ print length($0) " " $0; }' | sort -u | sort -rn | cut -d ' ' -f 2- | tac))

#    elif [[ $my_exit_code == 3 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#        echo -e "At least one or more URLs are unreachable!\n" >>$log_file

#        url_status_messages_all=($(tac $log_file \

#            | awk '/- End URL List -/{p=1; next} p && /- Start URL List -/{exit} p' \

#                | awk '{ print length($0) " " $0; }' | sort -u | sort -rn | cut -d ' ' -f 2- | tac))

#        ((health_counter++))

#    else

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtred} FAILED ${txtrst}]"

#        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#        ((error_count++))

#    fi

        

    # Ignore previous style url_status_messages_error[@];

    # Always display all URLs regardless of status.

    url_status_messages=("${url_status_messages_all[@]}")

    

    # Extract domain from URL.

    for url_string in ${url_status_messages[@]}; do

        url_domain_strings+=($(echo $url_string | awk -F "/" '{print $3}' | awk -F ":" '{print $1}'))

    done

     

    # Clean array to retain only the distinct domain URL strings.

    uniq_domain_strings=($(echo "${url_domain_strings[@]}" | tr ' ' '\n' | sort -ru))


    # Trim URL output for readability, and print as a tree.

#    if ((${#url_status_messages[@]} > 0)); then

#        for url_domain_string in ${uniq_domain_strings[@]}; do

#            echo -e "\t$url_domain_string"

#            url_branches=${#url_status_messages[@]}

#            for url_status in ${url_status_messages[@]}; do

#                if ((url_branches == 1)); then

#                   #tree_path_prefix="└──"

#                    tree_path_prefix="|->"

#

#                elif ((url_branches == ${#url_status_messages[@]}));then

#                   #tree_path_prefix="├──"

#                    tree_path_prefix="|->"

#                fi

#                echo -e "$url_status" | grep $url_domain_string \

#                    | cut -d '/' -f 4- | sed 's/ => //g' \

#                        | sed -e "s/OK/${txtgrn}  OK  ${txtrst}/g" \

#                            | sed -e "s/Error/${txtred}  Error  ${txtrst}/g" \

#                                | xargs -I "%" echo -e "\t$tree_path_prefix .../%"

#                ((url_branches--))

#            done

#        done

#    fi


#    IFS=$oIFS

#}


#check_opmn() # Checks the status of all OPMN  instances.

#{

#    local control_option=$1

#    local running_count=0

#    local my_script=$my_scripts/statusOHS.py

#    local my_exit_code=""

#    

#    oIFS=$IFS

#    IFS=':'

#    opmn_paths=($OPMN_HOMES)

#    IFS=""

#    opmn_paths=(${opmn_paths[@]})

#    IFS=$oIFS

#    

#    if [[ -z $OPMN_HOMES ]]; then

#      echo -e "   > OPMN process status ($s_hostname)   \t\t\c"

#      echo -e "[${txtylw}   NA   ${txtrst}]"

#      echo -e "\n[N/A] $FUNCNAME(): \c" >>$log_file

#      echo -e "There are no OPMN instances registered in this environment\n" >>$log_file

#      echo -e "\n\tThere are no OPMN instances registered\n"

#    elif ((${#opmn_paths[@]} > 0)); then         

#      echo -e "   > OPMN process status ($s_hostname)   \t\t\c"

#      echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#      for instance in ${opmn_paths[@]}; do

#          if [[ -d "$instance/bin" && $instance != "/" ]]; then

#              if (($($instance/bin/opmnctl status | grep -c "Alive") >= 1)); then

#                  echo -e "[INFO] $FUNCNAME(): \c" >>$log_file

#                  echo -e "Instance home $instance is running!" >>$log_file

#                  ((running_count++))

#              else

#                  echo -e "[WARNING] $FUNCNAME(): \c" >>$log_file

#                  echo -e "Instance home $instance is not running!" >>$log_file

#              fi

#          else

#              echo -e "[WARNING] $FUNCNAME(): \c" >>$log_file

#              echo -e "Skipping invalid instance $instance!" >>$log_file

#              ((warning_count++))

#              fi

#      done

#      if [[ $running_count ==  ${#opmn_paths[@]} ]]; then

#          echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#          echo -e "[${txtgrn}   OK   ${txtrst}]"

#          echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#          echo -e "All OHS processes are running on localhost!" >>$log_file

#      else

#          echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#          echo -e "[${txtylw} NOTICE ${txtrst}]"

#          echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#          echo -e "At least one OHS process is not running on localhost!" >>$log_file

#          ((warning_count++))

#      fi

#    else

#      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#      echo -e "[${txtred} FAILED ${txtrst}]"

#      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#      echo -e "Not able to find components in environment!\n" >>$log_file

#      ((error_count++))

#    fi

#    

#    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

#        i_name=0; for myhost in ${remote_hosts[@]}; do

#   if [[ -z $OPMN_HOMES ]]; then

#            echo -e "   > OPMN process status ($myhost)   \t\t\c"

#          echo -e "[${txtylw}   NA   ${txtrst}]"

#          echo -e "\n[N/A] $FUNCNAME(): \c" >>$log_file

#          echo -e "There are no OPMN instances registered in this environment\n" >>$log_file

#          echo -e "\n\tThere are no OPMN instances registered\n"

#   else 

#            echo -e "   > OPMN process status (${remote_aliases[$i_name]})   \t\t\c"

#            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" status_OPMN -r >/dev/null 2>&1

#            if (($?)); then

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtylw} NOTICE ${txtrst}]"

#                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#                echo -e "Something didn't go as planned; \c" >>$log_file

#                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

#                ((warning_count++))

#            else

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtgrn}   OK   ${txtrst}]"

#                echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#                echo -e "All OHS processes are running on $myhost; \c" >>$log_file

#                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

#            fi

#      fi

#        ((i_name++))

#        done

#    elif [[ $control_option == "-l" ]]; then

#        i_name=0; for myhost in ${remote_hosts[@]}; do

#            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

#            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}' \

#                ; grep $myhost_ip $temp_machine_file | awk -F ":" '{print $2}')

#            echo -e "   > OPMN process status (${remote_aliases[$i_name]})   \t\t\c"

#            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

#            echo -e "Retrieving component state for ${remote_aliases[$i_name]}" >>$log_file

#            $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#                $DOMAIN_NAME $my_nmport $myhost \

#                    $username $password $connect_type ${remote_aliases[$i_name]} >>$log_file 2>&1

#            my_exit_code=$?

#            if [[ $my_exit_code == 0 ]]; then

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtgrn}   OK   ${txtrst}]"

#                echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#                echo -e "OHS is running on ${remote_aliases[$i_name]}\n" >>$log_file

#            elif [[ $my_exit_code == 3 ]]; then

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtylw} NOTICE ${txtrst}]"

#                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#                echo -e "OHS is not running on ${remote_aliases[$i_name]}!\n" >>$log_file

#                ((health_counter++))

#            else

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtred} FAILED ${txtrst}]"

#                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#                echo -e "Error occurred running ${my_script##*/} for ${remote_aliases[$i_name]}!\n" >>$log_file

#                ((error_count++))

#            fi

#        ((i_name++))

#        done

#    fi

#}


check_health() # Performs overall sanity check(s).

{

    local check_option=$1

    

    health_counter=0

    

    echo -e " - Beginning health checks: \n" | tee -a $log_file

    

    case $check_option in

        adminserver)

            check_adminserver

            ;;

        managedservers)

            check_managedservers

            ;;

        systemcomponents)

            check_systemcomponents

            ;;

        nodemanager)

            check_nodemanager

            ;;

        opmn)

            check_opmn

            ;;

        domain)

            check_adminserver

            check_nodemanager -r

            check_managedservers

            check_systemcomponents

#            check_jdbc

#            check_deployments

#            check_composites

#     check_opmn -r

#            check_urls

            ;;

    esac

    

    if (($health_counter > 0)); then

        ((warning_count++))

        health_check="failed"

    else

        health_check="passed"

    fi

    

    echo -e "\n - Completed health checks." | tee -a $log_file 

}


is_adminserver() # Checks if AdminServer is configured to run on this machine.

{

####    echo -e " - Checking to see if this box is AdminServer: \t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    local listen_id=$(cat $temp_server_file | grep $ADMIN_SERVER_NAME | awk -F ":" '{print $2}')

    

    if [[ $listen_id != "All Local Addresses" ]]; then

        local listen_ip=$(getent hosts $listen_id | awk '{print $1}')

    fi

    

    if [[ -z $listen_id ]]; then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Error identifying AdminServer Listen Address; \c" >>$log_file

        echo -e "Possible non-standard configuration!\n" >>$log_file

        ((error_count++))

        set_exit 1

    elif [[ $listen_id == "All Local Addresses" ]]; then

    ###    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

           echo -e "[ OK ]"      

    ###   echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "$s_hostname is the AdminServer\n" >>$log_file 

        return 0

    elif [[ -z $listen_ip ]]; then

        listen_ip=$listen_id

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer IP address is '$listen_ip'" >>$log_file

    else

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer hostname is '$listen_id'" >>$log_file

    fi

    

    if (($((ifconfig -a || ip addr show) 2>/dev/null | grep -c $listen_ip) > 0)); then

      ###  echo -e "\b\b\b\b\b\b\b\b\b\b\c"

      ###  echo -e "[${txtgrn}   OK   ${txtrst}]"

           echo -e "[ OK ]"

        echo -e "[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "$s_hostname is the AdminServer\n" >>$log_file 

        return 0

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Please execute ${0##*/} on \c" >>$log_file

        echo -e "$listen_id!\n" >>$log_file

        ((error_count++))

        set_exit 1

    fi

}


start_adminserver() # Starts AdminServer if not already running on localhost.

{

    local my_script=$my_scripts/startAdmin.py


    echo -e " - Starting AdminServer: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports admin_server); then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer already running on $local_alias!\n" >>$log_file

        ((warning_count++))

    else

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

            $DOMAIN_NAME $DOMAIN_HOME $shared_nmport $HostName \

                $username $password $connect_type $ADMIN_SERVER_NAME >>$log_file 2>&1

        if (($?)); then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "AdminServer has been started on $local_alias\n" >>$log_file

        fi

    fi

}


stop_adminserver() # Stops AdminServer if already running on localhost.

{

    local my_script=$my_scripts/stopAdmin.py


    echo -e " - Stopping AdminServer: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"


    if (check_ports admin_server); then

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

            $DOMAIN_NAME $DOMAIN_HOME $shared_nmport $HostName \

                $username $password $connect_type $ADMIN_SERVER_NAME >>$log_file 2>&1

        if (($?)); then

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}; \c" >>$log_file

            echo -e "Trying another method, using stopWebLogic.sh!\n" >>$log_file

            ((warning_count++))

            $DOMAIN_HOME/bin/stopWebLogic.sh >>$log_file 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "A problem occurred while running stopWebLogic.sh!\n" >>$log_file

                ((error_count++))

            else

                while (check_ports admin_server); do

                    sleep 1

                done

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "AdminServer has been stopped on $local_alias\n" >>$log_file

            fi

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "AdminServer has been stopped on $local_alias\n" >>$log_file

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

}


start_managedservers() # Starts all the Managed Servers not running in this domain.

{

    local my_script=$my_scripts/startMS.py

    

    echo -e " - Starting Managed Servers: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports admin_server); then

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        if (($?)); then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "All Managed Servers have been started\n" >>$log_file

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

}


stop_managedservers() # Stops all Managed Servers running in this domain.

{

    local my_script=$my_scripts/stopMS.py

    

    echo -e " - Stopping Managed Servers: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports admin_server); then

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        if (($?)); then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "All Managed Servers have been stopped\n" >>$log_file

        fi 

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

}


start_nodemanager() # Starts the NodeManagers, applies to WebLogic Server 11g & 12c.

{

    local control_option=$1

    

    check_db

    

    echo -e " - Starting NodeManager(s) on localhost: \t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"  

    

    if (check_ports local_nm) && (check_ports shared_nm); then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "All Node Managers are already running on localhost!\n" >>$log_file

        ((warning_count++))

    else

        if [[ -f $DOMAIN_HOME/bin/startNodeManager.sh ]]; then

            nohup $DOMAIN_HOME/bin/startNodeManager.sh >>$log_file 2>&1 &

            if [[ ! -z $DOMAIN_HOME_M && $DOMAIN_HOME != $DOMAIN_HOME_M && \

                    -f $DOMAIN_HOME_M/bin/startNodeManager.sh ]]; then

                nohup $DOMAIN_HOME_M/bin/startNodeManager.sh >>$log_file 2>&1 &

            fi

        else

            local nm_home=$WLS_HOME/server/bin

            nohup $nm_home/startNodeManager.sh >>$log_file 2>&1 &

        fi

        until (check_ports shared_nm) && (check_ports local_nm); do

            sleep 1

        done

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "All NodeManagers have been started on $local_alias\n" >>$log_file

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Starting NodeManager on ${remote_aliases[$i_name]}: \t\t\c" | tee -a $log_file

#            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" start_NodeManager -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "NodeManager has been started; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    fi

}


stop_nodemanager() # Stops the NodeManagers, applies to WebLogic Server 11g & 12c.

{

    local control_option=$1


    echo -e " - Stopping NodeManager(s) on localhost: \t\t\c" | tee -a $log_file

    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports local_nm) || (check_ports shared_nm); then

        if [[ -f $DOMAIN_HOME/bin/stopNodeManager.sh ]]; then

            nohup $DOMAIN_HOME/bin/stopNodeManager.sh >>$log_file 2>&1 &

            if [[ ! -z $DOMAIN_HOME_M ]] && [[ $DOMAIN_HOME != $DOMAIN_HOME_M ]] && \

                [[ -f $DOMAIN_HOME_M/bin/stopNodeManager.sh ]]; then

                nohup $DOMAIN_HOME_M/bin/stopNodeManager.sh >>$log_file 2>&1 &

            fi

        else

            if [[ $OSTYPE == *"solaris"* ]]; then

                kill -15 $(netstat -anu | grep $local_nmport | grep "LISTEN" | awk '{print $4}')

                if [[ -n $shared_nmport ]] && [[ $local_nmport != $shared_nmport ]]; then

                    kill -15 $(netstat -anu | grep $shared_nmport | grep "LISTEN" | awk '{print $4}')

                fi

            elif [[ $OSTYPE == *"linux"* ]]; then

                kill -15 $(lsof -i:$local_nmport | grep "LISTEN" | awk '{print $2}')

                if [[ -n $shared_nmport ]] && [[ $local_nmport != $shared_nmport ]]; then

                    kill -15 $(lsof -i:$shared_nmport | grep "LISTEN" | awk '{print $2}')

                fi

            fi

        fi

        while (check_ports local_nm) || (check_ports shared_nm); do

            sleep 1

        done

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "NodeManagers have been stopped on $local_alias\n" >>$log_file

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "No NodeManagers are currently running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Stopping NodeManager on ${remote_aliases[$i_name]}: \t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" stop_NodeManager -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "NodeManager has been stopped; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    fi 

}


start_opmn() # Starts all Oracle HTTP Server instances.

{

    local control_option=$1

    local running_count=0

    local my_script=$my_scripts/startOHS.py

    

    oIFS=$IFS

    IFS=':'

    opmn_paths=($OPMN_HOMES)

    IFS=""

    opmn_paths=(${opmn_paths[@]})

    IFS=$oIFS

    

    echo -e " - Starting OPMN on localhost: \t\t\t\t\c" | tee -a $log_file

    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ -f  $DOMAIN_HOME_M/bin/startComponent.sh ]]; then

        if (check_ports local_nm); then 

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Starting OHS component for $s_hostname" >>$log_file

            $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                $DOMAIN_NAME $local_nmport $local_alias \

                    $username $password $connect_type $s_hostname >>$log_file 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "${my_script##*/} failed for $s_hostname!\n" >>$log_file

                ((error_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OHS has been started on $local_alias\n" >>$log_file

            fi

        else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "$local_alias:$local_nmport!\n" >>$log_file

                ((error_count++))

        fi         

        if [[ $control_option == "-r" ]]; then

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Remote execution will be done via WLST --not SSH\n" >>$log_file

            control_option="-l"

        fi

    elif ((${#opmn_paths[@]} > 0)); then         

        for instance in ${opmn_paths[@]}; do

            if [[ -d "$instance/bin" && $instance != "/" ]]; then

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "Instance home $instance" >>$log_file

                if (($($instance/bin/opmnctl status | grep -c "Alive") > 0)); then

                    echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                    echo -e "$instance is already running!" >>$log_file

                    ((warning_count++))

                else

                    $instance/bin/opmnctl startall >>$log_file 2>&1

                    if (($($instance/bin/opmnctl status | grep -c "Alive") > 0)); then

                        ((running_count++))

                    else

                        ((running_count--))

                    fi

                fi

            else

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Skipping invalid instance $instance!" >>$log_file

                ((warning_count++))

            fi

        done

        if [[ $running_count ==  0 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "All known ias-instances are already running!" >>$log_file

            ((warning_count++))

        elif [[ $running_count < ${#opmn_paths[@]} ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "Not all known ias-instances are running!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "OPMN has been started on $local_alias\n" >>$log_file

        fi    

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Not able to find components in environment!\n" >>$log_file

        ((error_count++))

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Starting OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" start_OPMN -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OPMN has been started; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    elif [[ $control_option == "-l" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Starting OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}')

            bash -c "cat </dev/null >/dev/tcp/$myhost_ip/$my_nmport" >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "$myhost:$my_nmport!\n" >>$log_file

                ((error_count++))

            else

                $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                    $DOMAIN_NAME $my_nmport $myhost \

                        $username $password $connect_type ${remote_aliases[$i_name]} >>$log_file 2>&1

                if (($?)); then

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtred} FAILED ${txtrst}]"

                    echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                    echo -e "${my_script##*/} failed for ${remote_aliases[$i_name]}!\n" >>$log_file

                    ((error_count++))

                else

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtgrn}   OK   ${txtrst}]"

                    echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                    echo -e "OHS has been started on ${remote_aliases[$i_name]}\n" >>$log_file

                fi

            fi

        ((i_name++))

        done

    fi

}


stop_opmn() # Stops all Oracle HTTP Server instances.

{

    local control_option=$1

    local running_count=0

    local my_script=$my_scripts/stopOHS.py

    

    oIFS=$IFS

    IFS=':'

    opmn_paths=($OPMN_HOMES)

    IFS=""

    opmn_paths=(${opmn_paths[@]})

    IFS=$oIFS

    

    echo -e " - Stopping OPMN on localhost: \t\t\t\t\c" | tee -a $log_file

    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ -f  $DOMAIN_HOME_M/bin/stopComponent.sh ]]; then

        if (check_ports local_nm); then

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Stopping OHS component for $s_hostname" >>$log_file

            $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                $DOMAIN_NAME $local_nmport $local_alias \

                    $username $password $connect_type $s_hostname >>$log_file 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "${my_script##*/} failed for $s_hostname!\n" >>$log_file

                ((error_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OHS has been stopped on $local_alias\n" >>$log_file

            fi

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "NodeManager is not running on \c" >>$log_file

            echo -e "$local_alias:$local_nmport!\n" >>$log_file

            ((error_count++))

        fi

        if [[ $control_option == "-r" ]]; then

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Remote execution will be done via WLST --not SSH\n" >>$log_file

            control_option="-l"

        fi

    elif ((${#opmn_paths[@]} > 0)); then         

        for instance in ${opmn_paths[@]}; do

            if [[ -d "$instance/bin" && $instance != "/" ]]; then

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "Instance home $instance" >>$log_file

                if (($($instance/bin/opmnctl status | grep -c "Alive") > 0)); then

                    instance_pid_list=($($instance/bin/opmnctl status | grep "Alive" | awk '{print $5}'))

                    $instance/bin/opmnctl stopall >>$log_file 2>&1

                    for instance_pid in ${instance_pid_list[@]}; do

                        if (kill -0 $instance_pid 2>/dev/null); then

                            kill -9 $instance_pid

                            ((running_count--))

                        else

                            ((running_count++))

                        fi

                    done

                else

                    echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                    echo -e "$instance is not currently running!" >>$log_file

                    ((warning_count++))

                fi

            else

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Skipping invalid instance $instance!" >>$log_file

                ((warning_count++))

            fi

        done

        if [[ $running_count == 0 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "All known ias-instances are already stopped!" >>$log_file

            ((warning_count++))

        elif [[ $running_count < ${#opmn_paths[@]} ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "Had to forcefully kill ias-instance processes!\n" >>$log_file

            ((warning_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "OPMN has been stopped on $local_alias\n" >>$log_file

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Not able to find components in environment!\n" >>$log_file

        ((error_count++))

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Stopping OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" stop_OPMN -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OPMN has been stopped on $myhost; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    elif [[ $control_option == "-l" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Stopping OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}')

            bash -c "cat </dev/null >/dev/tcp/$myhost_ip/$my_nmport" >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "${remote_aliases[$i_name]}:$my_nmport!\n" >>$log_file

                ((error_count++))

            else

                $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                    $DOMAIN_NAME $my_nmport $myhost \

                        $username $password $connect_type ${remote_aliases[$i_name]} >>$log_file 2>&1

                if (($?)); then

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtred} FAILED ${txtrst}]"

                    echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                    echo -e "$${my_script##*/} failed for ${remote_aliases[$i_name]}!\n" >>$log_file

                    ((error_count++))

                else

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtgrn}   OK   ${txtrst}]"

                    echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                    echo -e "OHS has been stopped on ${remote_aliases[$i_name]}\n" >>$log_file

                fi

            fi

        ((i_name++))

        done

    fi

}


fmw_srvctl() # Principal wrapper function --all available commands: 

{    

    case $control_command in

        start_Domain)

            get_context

            is_adminserver

            check_ssh

            start_nodemanager -r

            start_adminserver

            if [[ $instance_type == *"oid_domain"* ]]; then

                start_opmn -r

                start_managedservers

            elif [[ $instance_type == *"oam_domain"* ]]; then

                start_managedservers

                start_opmn -r

            else

                start_opmn -r

                start_managedservers

            fi

            if [[ $control_session != "-m" ]]; then    

                check_health domain

            fi    

            ;;

        stop_Domain)

            get_context

            is_adminserver

            check_ssh

            stop_managedservers

            stop_adminserver

            stop_opmn -r

            stop_nodemanager -r

            ;;

        restart_Domain)

            get_context

            is_adminserver

            check_ssh

            stop_managedservers

            stop_adminserver

            stop_opmn -r

            stop_nodemanager -r

            start_nodemanager -r

            start_adminserver

            if [[ $instance_type == *"oid_domain"* ]]; then

                start_opmn -r

                start_managedservers

            elif [[ $instance_type == *"oam_domain"* ]]; then

                start_managedservers

                start_opmn -r

            else

                start_opmn -r

                start_managedservers

            fi

            if [[ $control_session != "-m" ]]; then    

                check_health domain

            fi

            ;;

        status_Domain)

            get_context

            is_adminserver

#            check_ssh

            check_health domain

            ;;

        start_AdminServer)

            start_adminserver

            ;;

        stop_AdminServer)

            stop_adminserver

            ;;

        restart_AdminServer)

            stop_adminserver

            start_adminserver

            ;;

        status_AdminServer)

            check_health adminserver

            ;;

        start_ManagedServers)

            start_managedservers

            ;;

        stop_ManagedServers)

            stop_managedservers

            ;;

        restart_ManagedServers)

            stop_managedservers

            start_managedservers

            ;;

        status_ManagedServers)

            check_health managedservers

            ;;

        start_NodeManager)

            start_nodemanager

            ;;

        stop_NodeManager)

            stop_nodemanager

            ;;

        restart_NodeManager)

            stop_nodemanager

            start_nodemanager

            ;;

        status_NodeManager)

            check_health nodemanager

            ;;

        start_OPMN)

            start_opmn

            ;;

        stop_OPMN)

            stop_opmn

            ;;

        restart_OPMN)

            stop_opmn

            start_opmn

            ;;

        status_OPMN)

            check_health opmn

            ;;

        *)

            echo -e "\nInvalid option(s)"

            show_usage

    esac

}


get_my_name() # Who you are logged in as?

{

    # For logging purposes record who is associated with stdin, daemon, or odcagent.

    if [[ -n $(logname) ]]; then

        user_id=$(logname)

    elif [[ -n $(who is there | awk '{print $1}') ]]; then

        user_id=$(who commands me | awk '{print $1}')

    else

        user_id=$USER

    fi

}


phone_home() # E-mails OMCS/FMW Team when invoked, as a counter mechanism.

{    

    local exit_status=$1

    

    #to_address="omcs_wlsautostart_events_grp@oracle.com"

    if [[ $source_dir == *"prod"* ]]; then

        to_address="-c david.sorgi@oracle.com"

    else

        to_address="david.sorgi@oracle.com"

    fi

    

    if [[ $control_session == "-d" ]]; then

        session_type="daemon init.d script"

        user_id="$session_type"

    elif [[ $control_session == "-e" ]]; then

        session_type="CA (EM) triggered event"

        user_id="$session_type"

     elif [[ $control_session == "-m" ]]; then

        session_type="MCollective daemon"

        user_id="$session_type"

    fi

    

    case $exit_status in

        Error)

            subject="[${0##*/}] $control_command ran with errors on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type failed on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

            ;;

        Success)

            subject="[${0##*/}] $control_command ran successfully on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type succeeded on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

            ;;

        Terminated)

            subject="[${0##*/}] $control_command was aborted on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type terminated on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

            ;;

        Warning)

            subject="[${0##*/}] $control_command ran with warnings on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type succeeded on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

    esac

    

    if [[ $control_session != "-r" ]]; then

        echo -e "$message_body" | mailx -s "$subject" $to_address

    fi

}


set_exit() # Report exit status message(s) before terminating.

{

    local return_status=$1

    

    end_time=$(date +%s)

    run_time=$(($end_time - $start_time))

    

    if [[ -w $log_file ]]; then

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "Wrapping up session!\n" >>$log_file

    fi

    

    if [[ -z $debug_message ]]; then

        if (($error_count > 0)) || (($warning_count > 0)); then

            debug_message=$(tac $log_file \

                | awk '/ Wrapping up /{p=1; next} p && / Session Start /{exit} p' \

                    | grep -E "\[CRITICAL\]|\[WARNING\]" | tac)

        elif [[ $health_check == "passed" ]]; then

            debug_message=$(tac $log_file \

                    | awk '/ Wrapping up /{p=1; next} p && / Session Start /{exit} p' \

                        | grep "\[INFO\] check_health" | tac)

        fi

    fi

    

    if (($error_count > 0)); then

        return_status=1

    elif (($warning_count > 0)); then

        return_status=246

    fi

        

    case $return_status in

        0)

            phone_home "Success"

            ;;

        1)

            phone_home "Error"

            ;;

        2)

            log_file='/dev/null'

            ;;

        126)

            log_file='/dev/null'

            phone_home "Error"

            ;;

        246)

            phone_home "Warning"

            ;;

        *)

            return_status=130

            debug_message+="[CRITICAL] ${FUNCNAME[1]}(): "

            debug_message+="User must've pressed Ctrl+C "

            debug_message+="or process was killed by some other force!"

            phone_home "Terminated"

    esac

    

    if [[ -n $debug_message && $return_status != 0 ]]; then

        echo -e "\n$debug_message"

    fi 

    

###    if [[ $return_status != 2 ]]; then

#        echo -e "\nTotal run time for $instance_type: \c" | tee -a $log_file

#        echo -e "$(($run_time / 60)) minutes and \c" | tee -a $log_file

#        echo -e "$(($run_time % 60)) seconds." | tee -a $log_file

#        echo -e "Instance: $instance_name => Host: $f_hostname\n" | tee -a $log_file

#        if [[ $return_status != 126 ]]; then

#            echo -e "${0##*/} may have written additional warning messages."

#            echo -e "For more information, please check: ${txtunl}$log_file${txtrst}\n"

#        fi

#        echo -e "$(date) :: ${0##*/} is exiting with status \c" | tee -a $log_file

#        echo -e "$return_status\n" | tee -a $log_file

#        echo -e "========== OMCS OneCommand Session End ===========\n" >>$log_file

##    fi

    

    # Prompt Control: For interactive shells, give the cursor back (show).

###    if [[ -t 0 || -p /dev/stdin ]]; then

  #     tput cnorm || tput ve >/dev/null 2>&1

 ##   fi

    

    exit $return_status

}


# Prompt Control: For interactive shells, take the cursor away (hide).

if [[ -t 0 || -p /dev/stdin ]]; then

  tput civis || tput vi >/dev/null 2>&1

fi


# Trap Ctrl+C or similar process termination request.

trap set_exit SIGINT SIGTERM


# This in Main:

if [[ -z $2 || $2 == "-d" || $2 == "-e" || $2 == "-m" || $2 == "-r" ]]; then

    case $1 in

        -h|--help|-help|--?|-?|"")

            show_usage

            ;;

        *)

##            hello

            unset_env

            get_my_name

            get_my_version

            set_wls_properties

            set_logging

            fmw_srvctl $1

    esac

else

    echo -e "\nInvalid option(s)"

    show_usage

fi


set_exit 0


No comments:

Post a Comment

Google, Mozilla, and Apple choosing to no longer support Entrust as a publicly trusted certificate authority

Google, Mozilla, and Apple have all decided to stop trusting Entrust’s publicly issued certificates after specific cutoff dates , due to lon...