Skip to content

Instantly share code, notes, and snippets.

@AKSarav
Last active July 20, 2022 13:32
Show Gist options
  • Save AKSarav/8f8ba1da3afa647d11bdb3ac523fb823 to your computer and use it in GitHub Desktop.
Save AKSarav/8f8ba1da3afa647d11bdb3ac523fb823 to your computer and use it in GitHub Desktop.
WLPS.sh
#!/bin/bash
#
#
#
BASE_DIR=`dirname $0`
SCRIPT=$0
_processinfo_()
{
TECH=`echo $1|tr [a-z] [A-Z]`
if [ $TECH == "JAVAA" ]
then
TECH="JAVA"
fi
echo -e "\nPROCESS COUNT:" $PROC_COUNT
#MATCHING THE TECHNOLOGY AND PRINTING THE PID AND INSTANCENAME HEADER
if [[ $TECH == "WEBLOGIC" ]]
then
echo "----------------------------------------------------------------------------------------------------------------------"
echo -e "PID INSTANCENAME ADMINURL DOMAIN PORTS"|awk '{ printf "%-10s%-30s%-30s%-40s%s\n",$1,$2,$3,$4,$5}'
echo "----------------------------------------------------------------------------------------------------------------------"
fi
index=0
for line in "$@"
do
PID=$line
#[[ $index -ne 0 ]] && echo $line
#index=`echo $index + 1|bc`
# IGNORING THE UID
if [[ "$line" =~ [a-z] ]]
then
continue
fi
#MATCHING THE TECHNOLOGY
if [ "$TECH" == "WEBLOGIC" ]
then
# PRINTING THE INSTANCE NAME AND PID
#PORTSUSED=`netstat -ntlp 2>/dev/null|grep -i $PID|awk '{print $4}'|grep -o "\:[0-9]*$"|tr -d [:]|tr "\n" ","|sed 's/,$/\n/'`
#Updated to remove duplicates
#PORTSUSED=`netstat -ntlp 2>/dev/null|grep -i $PID|awk '{print $4}'|grep -o "\:[0-9]*$"|uniq|tr -d [:]|tr "\n" ","|sed 's/,$/\n/'`
ISITSERVER=`ps -feww|grep -i $PID|grep -i weblogic.Server|grep -v grep|wc -l`
if [[ $ISITSERVER > 0 ]]
then
INSTANCE=`ps -feww|grep -i $line|grep -v grep|grep -io "weblogic.Name=.*"|awk '{FS=" "; print $1}'|cut -d "=" -f2`
JAVA_LOC=`ps -feww|grep -i $line|grep -v grep|awk '{print $8}'`
## Write script file to give as input to JMXTERM
jmxcommands()
{
echo "open $PID"
echo "bean com.bea:Name=$INSTANCE,Type=ServerRuntime"
echo "get AdminServerHost"
echo "get AdminServerListenPort"
echo "get AdminServerListenPortSecure"
echo "get CurrentDirectory"
echo "close"
}
jmxcommands > jmxterm.input
## Execute the Created JMX script using JMXTERM
$JAVA_LOC -jar jmxterm-1.0-alpha-4-uber.jar -v silent -n < jmxterm.input > jmxterm.output
while IFS= read -r var
do
# echo $var
key=`echo $var|awk '{print $1}'`
case $key in
"AdminServerHost") ASH=`echo $var|awk '{print $3}'|sed 's/\;//g'` ;;
"AdminServerListenPort") ASLP=`echo $var|awk '{print $3}'|sed 's/\;//g'`;;
"AdminServerListenPortSecure") ASLPS=`echo $var|awk '{print $3}'|sed 's/\;//g'`;;
"CurrentDirectory") CDIR=`echo $var|awk '{print $3}'|sed 's/\;//g'`;;
esac
done < jmxterm.output
if [[ $ASH != "" || $ASLP != "" || $ASLPS != "" || $CDIR != "" ]]
then
#Build AdminURL
if [ $ASLPS == "false" ]
then
PROTO="t3://"
elif [ $ASLPS == "true" ]
then
PROTO="t3s://"
fi
AURL=$PROTO$ASH":"$ASLP
else
AURL="notfound";
CDIR="notfound"
fi
echo "$PID $INSTANCE $AURL $CDIR $PORTSUSED"|awk '{ printf "%-10s%-30s%-30s%-40s%s\n",$1,$2,$3,$4,$5}'
else
echo -e "$PID NodeManager NA NA $PORTSUSED"|awk '{ printf "%-10s%-30s%-30s%-40s%s\n",$1,$2,$3,$4,$5}'
fi
fi
#RE INDEX VARIABLES
AURL="";CDIR="";ASH="";ASLP="";ASLPS="";
done
echo "----------------------------------------------------------------------------------------------------------------------"
}
echo -e " \nWEBLOGIC PROCESS INFORMATION - WLPS\n"
CUR_TIME=`date`
BOXINFO=`uname -r`
echo "------------------------------------------------"
echo -e "Box Information"
echo "------------------------------------------------"
printf "%-10s: %s\n" "BoxName" `uname -n`
printf "%-10s: %s\n" "Starttime" "$CUR_TIME"
printf "%-10s: %s" "KernalInfo" "$BOXINFO"
echo -e "\n------------------------------------------------"
WLS_PROC='ps -feww|grep -i java|egrep -i "weblogic.Server|weblogic.Nodemanager"|grep -v grep'
PROC_COUNT=`eval $WLS_PROC|wc -l`
if [ $PROC_COUNT -ne 0 ]
then
echo -e "\n\nWLPS-WeblogicProcessStatus Script found some processes to report"
echo "Please wait"
sleep 30
PIDS=`eval $WLS_PROC|awk '{print $2}'`
_processinfo_ weblogic $PIDS
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment