Shell Script to check Weblogic Admin and Managed Servers
In this post I am sharing a script to check the Weblogic and Managed Server status Using Shell script and WLST script.
Assumptions:
Understanding for Shell script
UnderStand Fusion MiddbleWare
Script:
This script is tested in EBS 12.2 Environment. You can change values as per your environment.
#!/bin/bash#set -x. /u01/install/APPS/EBSapps.env run# Set WebLogic Environment Variablesexport MW_HOME=/u01/install/APPS/fs1/FMW_Homeexport WL_HOME=$MW_HOME/wlserver_10.3export DOMAIN_HOME=$MW_HOME/user_projects/domains/EBS_domainexport PATH=$PATH:$WL_HOME/common/bin# WebLogic Admin Server credentialsADMIN_URL="t3://apps.example.com:7001"USERNAME="weblogic"PASSWORD="welcome1"# Temporary file to store WLST scriptWLST_SCRIPT="/tmp/check_wls_status.py"# Temporary file to store WLST scriptWLST_SCRIPT="/tmp/check_wls_status.py"# Colors for outputRED='\033[0;31m'NC='\033[0m' # No Color# Function to create WLST script for checking server statuscreate_wlst_script() {cat <<EOF > $WLST_SCRIPTconnect('$USERNAME', '$PASSWORD', '$ADMIN_URL')domainRuntime()# Function to check the status of a serverdef check_server_status(serverName):cd('/ServerLifeCycleRuntimes/' + serverName)state = cmo.getState()if state == "RUNNING":print('Server: ' + serverName + ' - State: ' + state)else:print('DOWN: ' + serverName + ' - State: ' + state)# List of servers to checkservers = cmo.getServerLifeCycleRuntimes()for server in servers:serverName = server.getName()check_server_status(serverName)disconnect()exit()EOF}# Function to execute WLST script and process the outputexecute_wlst_script() {$WL_HOME/common/bin/wlst.sh $WLST_SCRIPT | while IFS= read -r line; doif [[ $line == DOWN:* ]]; thenecho -e "${RED}${line}${NC}"elseecho "$line"fidone}# Main function to monitor WebLogic serversmonitor_weblogic() {echo "Monitoring WebLogic Admin and Managed Servers..."create_wlst_scriptexecute_wlst_scriptrm -f $WLST_SCRIPT}# Call the main functionmonitor_weblogic
Execution of Script:
sh monitor_weblogic.sh
Post a Comment
Post a Comment