Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Tuxedo info -Domains running, IPC resources, unix ports & more

Status
Not open for further replies.

RobJordan

MIS
Apr 3, 2001
296
US
#!/usr/bin/ksh
#
# Date: 5/16/01
# Name: tuxtool
# Ver: 1.4
# Author: Robert G. Jordan Robert@JORDAN2000.com
# Purpose: Display useful Tuxedo info (Domains running, IPC resources, unix ports, etc.) and log to a file
# To Run: tuxtool
# (an interactive menu will launch)
#
# note: requires lsof utility to display tcp info and base dir info about domain
#
# 08/13/01 - 1.2 Added feature to try and detect tuxedo version - R. Jordan
# 08/22/01 - 1.3 Fixed bug for finding BASE_DIR value - R. Jordan
# 03/01/02 - 1.4 Added Validate function
#
################################################################################

################################################################################
# Variables
################################################################################

TMP_LIST=/tmp/TMP_LIST.$$ # generic tmp file for data
COLUMNS=1 # Number of columns for menus
MAX_ROWS=50 # Max rows per page for menus
MAX_LINE=80 # Max line length
HEX_2_DEC=/tmp/HEX_2_DEC.$$.tmp # temp file for hex to dec conversion for ipc key
LOG_FILE=/tmp/tuxtool.log.$$.tmp # results are written this log file
HOST_NAME=`/usr/bin/hostname` # capture hostname for log file
CUR_DATE=`/usr/bin/date` # capture date for log file

################################################################################
# Functions
################################################################################

Write () # Display a message on screen and log to a file
# usage: Write "[Your message here]"
{
MESSAGE="$1"
eval "echo \"$MESSAGE\""|tee -a $LOG_FILE
}


Validate () # validate that commands or resources are available for script to use
# Validate $1 r (test if file or dir is readable)
# Validate $1 rw (test if file or dir is readable and writable)
# Validate $1 rx (test if file is readable and executable)
# $1 is file or command to test, $2 can be r, rw or rx
# ex: Validate /usr/bin/ls rx
{
case $2 in
r)
if test -a $1
then
FOUND="true"
else
echo "WARNING: $1 not found"
fi
if test -r $1
then
FOUND="true"
else
echo "WARNING: $1 is not readable"
exit 1
fi
;;

rw)
if test -a $1
then
FOUND="true"
else
echo "WARNING: $1 not found"
fi
if test -w $1
then
FOUND="true"
else
echo "WARNING: $1 is not writable"
exit 1
fi
;;
rx)
if test -a $1
then
FOUND="true"
else
echo "WARNING: $1 not found"
fi
if test -x $1
then
FOUND="true"
else
echo "WARNING: $1 is not executable"
exit 1
fi
;;
*)
echo "Improper use of Validate function!"
echo $*
echo "Please view function comments for usage"
exit 1
;;
esac
}

Create_Menu () # display menu from a list and get user input
# requires one to three arguments: LIST_NAME and MENU_TITLE_ONE(optional) and MENU_TITLE_TWO(optional)
# returns MENU_VALUE
{
# clear
LIST=$1
MENU_TITLE_ONE=$2
MENU_TITLE_TWO=$3
IM_DONE="false"
ALL="false"
LIST_COUNT=`cat $LIST|wc -l`
until [ "$IM_DONE" = "true" ] # loop until valid input is received
do

MENU_COUNTER=1 # initialize counter
echo ""
echo " $MENU_TITLE_ONE"
echo ""
echo " $MENU_TITLE_TWO"
echo "--------------------------------------------------------------------------------"

ROWS=0
LINE_LENGTH=0
FORMAT_COUNTER=0
LIST_COUNT=`expr $LIST_COUNT + 1`

cat $LIST|while read LINE
do
FORMAT_COUNTER=`expr $FORMAT_COUNTER + 1`

if [ $MENU_COUNTER -lt 1000 ] # add no extra spaces for triple-digit menu number
then
SPACES=""
fi

if [ $MENU_COUNTER -lt 100 ] # add one extra space for double-digit menu number
then
SPACES=" "
fi

if [ $MENU_COUNTER -lt 10 ] # add two extra spaces for single-digit menu number
then
SPACES=" "
fi

STRING=`echo "${MENU_COUNTER}) ${SPACES}${LINE}"`
Check_Line

if [ $FORMAT_COUNTER -eq $COLUMNS ] # formats based on value of COLUMNS
then
echo "$STRING"
LINE_LENGTH=0
FORMAT_COUNTER=0
ROWS=`expr $ROWS + 1`
else
case ${#LINE} in # determine number of tabs to add based on item length
[0-9]|[1][0-5])
echo "$STRING\t\t\c"
;;
[1][6-9]|[2][0-9])
echo "$STRING\t\c"
;;
*)
echo "$STRING\c"
;;
esac
fi

MENU_COUNTER=`expr $MENU_COUNTER + 1`

if [ $ROWS -eq $MAX_ROWS ]
then
echo ""
echo "Press [RETURN/ENTER KEY] to see more choices."
ROWS=0
read PAUSE
fi
done

echo "$MENU_COUNTER) -- ALL --"
ALL=$MENU_COUNTER
MENU_COUNTER=`expr $MENU_COUNTER + 1`
echo "$MENU_COUNTER) -- Exit --"
EXIT=$MENU_COUNTER

# get user's menu choice

echo "#? \c"
read MENU_CHOICE
if [ "$MENU_CHOICE" = "$EXIT" ]
then
Exit
fi

if [ "$MENU_CHOICE" = "$ALL" ]
then
IM_DONE="true"
ALL="true"
break
fi

MENU_COUNTER=1

cat $LIST|while read LINE
do
if [ "$MENU_CHOICE" = "$MENU_COUNTER" ]
then
MENU_VALUE=$LINE
IM_DONE="true"
break
fi

MENU_COUNTER=`expr $MENU_COUNTER + 1`
done
done
}


Check_Line () # add line wrapping for menu items
{
LINE_LENGTH=`expr $LINE_LENGTH + ${#STRING}`

if [ $LINE_LENGTH -gt $MAX_LINE ] # add extra carriage return if line gets too long
then
echo ""
ROWS=`expr $ROWS + 1`
FORMAT_COUNTER=0
LINE_LENGTH=0
fi
}

Exit () # user seleted exit
{
echo
echo "Results can be found in $LOG_FILE"
echo
exit 0
}

Find_BBLs ()
{
echo "Finding BBLs..."
/usr/bin/ps -ef|grep " BBL "|grep -v grep|sort >> $TMP_LIST.BBL_PS
BBL_COUNT=`cat $TMP_LIST.BBL_PS|wc -l`
if [ $BBL_COUNT -lt 1 ]
then
echo
echo "WARNING: No BBL processes found! Aborting!"
Exit
fi

cat $TMP_LIST.BBL_PS|while read BBL_PS_LINE
do
BBL_PID=`echo $BBL_PS_LINE|awk '{print $2}'`
BBL_OWNER=`echo $BBL_PS_LINE|grep " $BBL_PID "|grep " BBL "|awk '{print $1}'`
DOMAIN_ID=`echo $BBL_PS_LINE|grep " $BBL_PID "|grep " BBL "|awk -F" dom=" '{print $2}'|awk '{print $1}'`
if [ ${#DOMAIN_ID} -lt 1 ]
then
DOMAIN_ID="**MISSING!**"
fi
echo "$BBL_PID\t$BBL_OWNER\t\t$DOMAIN_ID" >> $TMP_LIST.BBL_MENU
done
}

BBL_Menu ()
{
LIST=$TMP_LIST.BBL_MENU
MENU_COUNT=`cat $LIST|wc -l`
Create_Menu "$LIST" "BBL MENU" "PID\tOWNER\t\tDOMAIN ID"
BBL_PID=`echo $MENU_VALUE|awk '{print $1}'`
BBL_OWNER=`echo $MENU_VALUE|awk '{print $2}'`
DOMAIN_ID=`echo $MENU_VALUE|awk '{print $3}'`
}

Domain_Details ()
{
Find_IPC_Key
Write ""
Write "********************************************************************************"
Write "DOMAIN ID:\t$DOMAIN_ID"

BASE_DIR=`cat $TMP_LIST.LSOF_TCP|grep " $BBL_PID "|grep "BBL "|grep VDIR|awk '{print $9}'|awk -F "/bin" '{print $1}'`
> $TMP_LIST.FIND

if [ ${#BASE_DIR} -gt 0 ]
then
find $BASE_DIR -follow > $TMP_LIST.FIND
UBB_CONFIGS=`grep -i ubb $TMP_LIST.FIND`
UBB_CURRENT=`ls -t $UBB_CONFIGS|head -1`
TUX_VER=`cat $UBB_CURRENT|grep TUXDIR|grep -v "#"|awk -F"=" '{print $2}'`
else
UBB_CURRENT="???"
BASE_DIR="???"
TUX_VER="???"
fi

Write "BASE DIR:\t$BASE_DIR"
Write "UBB CONFIG:\t$UBB_CURRENT"
Write "TUX VER:\t$TUX_VER"

> $TMP_LIST.UBB_CONFIGS
> $TMP_LIST.LS_UBB_CONFIGS
> $TMP_LIST.SORTED_LS_UBB_CONFIGS

Write "BBL PID:\t$BBL_PID"
Write "BBL OWNER:\t$BBL_OWNER"
NAME=`finger $BBL_OWNER|sort -u|grep "In real life:"|awk -F"In real life: " '{print $2}'`
PHONE=`finger $BBL_OWNER|sort -u|grep "Work phone:"|awk -F"Work phone: " '{print $2}'`
Write "NAME:\t\t$NAME"
Write "PHONE:\t\t$PHONE"
Write "IPC KEY HEX:\t0x$IPC_KEY_HEX"
Write "IPC KEY DEC:\t$IPC_KEY_DEC"

cat $TMP_LIST.GWT_PS|grep $DOMAIN_ID|while read LINE
do
Write "--------------------------------------------------------------------------------"
GWT_PID=`echo $LINE|awk '{print $2}'`
GWT_PORT=`cat $TMP_LIST.LSOF_TCP|grep " $GWT_PID "|grep LISTEN|awk -F":" '{print $2}'|awk '{print $1}'`
Write "GWTDOMAIN PID:\t$GWT_PID\t\tGWTDOMAIN PORT:\t$GWT_PORT"

cat $TMP_LIST.LSOF_TCP|grep ":$GWT_PORT "|grep ESTABLISHED|awk -F"->" '{print $1}'|awk '{print $NF}'|while read LINE2
do
Write " CLIENT: $LINE2"
done
done



cat $TMP_LIST.WSL_PS|grep $DOMAIN_ID|while read LINE
do
Write "--------------------------------------------------------------------------------"
WSL_PID=`echo $LINE|awk '{print $2}'`
WSL_PORT=`cat $TMP_LIST.LSOF_TCP|grep " $WSL_PID "|grep LISTEN|awk -F":" '{print $2}'|awk '{print $1}'`
Write "WSL PID:\t$WSL_PID\t\tWSL PORT:\t$WSL_PORT"
cat $TMP_LIST.WSH_PS|grep " $WSL_PID "|while read LINE
do
WSH_PID=`echo $LINE|awk '{print $2}'`
WSH_PORT=`cat $TMP_LIST.LSOF_TCP|grep " $WSH_PID "|grep LISTEN|awk -F":" '{print $2}'|awk '{print $1}'`
Write " WSH PID:\t $WSH_PID\t\t WSH PORT:\t $WSH_PORT"
cat $TMP_LIST.LSOF_TCP|grep ":$WSH_PORT "|grep ESTABLISHED|awk -F"->" '{print $1}'|awk '{print $NF}'|while read LINE2
do
Write " CLIENT: $LINE2"
done
done
done

cat $TMP_LIST.JSL_PS|grep $DOMAIN_ID|while read LINE
do
Write "--------------------------------------------------------------------------------"
JSL_PID=`echo $LINE|awk '{print $2}'`
JSL_PORT=`cat $TMP_LIST.LSOF_TCP|grep " $JSL_PID "|grep LISTEN|awk -F":" '{print $2}'|awk '{print $1}'`
Write "JSL PID:\t$JSL_PID\t\tJSL PORT:\t$JSL_PORT"
cat $TMP_LIST.JSH_PS|grep " $JSL_PID "|while read LINE
do
JSH_PID=`echo $LINE|awk '{print $2}'`
JSH_PORT=`cat $TMP_LIST.LSOF_TCP|grep " $JSH_PID "|grep LISTEN|awk -F":" '{print $2}'|awk '{print $1}'`
Write " JSH PID:\t $JSH_PID\t\t JSH PORT:\t $JSH_PORT"
cat $TMP_LIST.LSOF_TCP|grep ":$JSH_PORT "|grep ESTABLISHED|awk -F"->" '{print $1}'|awk '{print $NF}'|while read LINE2
do
Write " CLIENT: $LINE2"
done
done
done
}

Find_IPC_Key () #find ipc key and translate from hex to dec - requires $BBL_PID to be set
{
echo "obase=10" > $HEX_2_DEC
echo "ibase=16" >> $HEX_2_DEC

IPC_KEY_HEX=`ipcs -am|grep " $BBL_PID "|grep " 0x"|grep -v "0x00000000 "|head -1|awk '{print $3}'|awk -F"0x" '{print $2}'`

IPC_KEY_HEX_UPPER=`echo $IPC_KEY_HEX|tr [a-z] [A-Z]`
echo $IPC_KEY_HEX_UPPER >> $HEX_2_DEC
echo "quit" >> $HEX_2_DEC
IPC_KEY_DEC=`bc $HEX_2_DEC`

# sleep 1
}



Find_WSLs ()
{
echo "Finding WSLs..."
/usr/bin/ps -ef|grep " WSL "|grep -v grep|sort >> $TMP_LIST.WSL_PS
}

Find_WSHs ()
{
echo "Finding WSHs..."
/usr/bin/ps -ef|grep " WSH "|grep -v grep|sort >> $TMP_LIST.WSH_PS
}

Find_JSLs ()
{
echo "Finding JSLs..."
/usr/bin/ps -ef|grep " JSL "|grep -v grep|sort >> $TMP_LIST.JSL_PS
}

Find_JSHs ()
{
echo "Finding JSHs..."
/usr/bin/ps -ef|grep " JSH "|grep -v grep|sort >> $TMP_LIST.JSH_PS
}

Find_GWTs ()
{
echo "Finding GWTDOMAINs..."
/usr/bin/ps -ef|grep " GWTDOMAIN "|grep -v grep|sort >> $TMP_LIST.GWT_PS
}

Run_lsof ()
{
echo "Running lsof... this may take a minute or two... :v("
/usr/local/bin/lsof -V >> $TMP_LIST.LSOF
}

Find_TCP ()
{
echo "Scanning TCP ports..."
cat $TMP_LIST.LSOF|egrep "TCP|VDIR"|sort >> $TMP_LIST.LSOF_TCP
}

Find_TUX_Ver ()
{
echo "Scanning TUX versions..."
cat $TMP_LIST.LSOF|egrep "tux64|tux65|tux71"|grep "BBL" >> $TMP_LIST.LSOF_TUX
}

Check_ID ()
{
ID=`whoami`
if [ $ID = "root" ]
then
ID="ok"
else
echo "WARNING: you are not root user."
echo "tuxtool will not be able to display all domain information."
echo
echo "Please press [RETURN/ENTER] to continue."
read PAUSE
echo
fi
}

Check_lsof ()
{
if test -x /usr/local/bin/lsof
then
LSOF="ok"
else
echo "WARNING: /usr/local/bin/lsof cannot be executed."
echo "tuxtool will not be able to display all domain information."
echo
echo "Please press [RETURN/ENTER] to continue."
read PAUSE
echo
fi
}

################################################################################
# Main
################################################################################

VERSION=`head -5 tuxtool|grep Ver:|awk '{print $3}'`
echo "Thank you for using tuxtool version $VERSION"
echo "The latest version can always be found echo "Please send any questions/comments to Robert@JORDAN2000.com"
echo

Validate /tmp rw
Validate /usr/bin/awk rx
Validate /usr/bin/bc rx
Validate /usr/bin/cat rx
Validate /usr/bin/echo rx
Validate /usr/bin/egrep rx
Validate /usr/bin/expr rx
Validate /usr/bin/find rx
Validate /usr/bin/finger rx
Validate /usr/bin/grep rx
Validate /usr/bin/head rx
Validate /usr/bin/ipcs rx
Validate /usr/bin/ls rx
Validate /usr/bin/more rx
Validate /usr/bin/ps rx
Validate /usr/bin/read rx
Validate /usr/bin/sort rx
Validate /usr/bin/tee rx
Validate /usr/bin/test rx
Validate /usr/bin/view rx
Validate /usr/bin/wc rx

Check_ID
Check_lsof

echo "Searching for running Tuxedo domains..."
Find_BBLs
Find_GWTs
Find_WSLs
Find_WSHs
Find_JSLs
Find_JSHs
Run_lsof
Find_TCP
Find_TUX_Ver

IM_DONE_2="false"
until [ $IM_DONE_2 = "true" ]
do
BBL_Menu
echo "HOSTNAME:\t$HOST_NAME" > $LOG_FILE
echo "DATE:\t\t$CUR_DATE" >> $LOG_FILE
if [ $ALL = "true" ]
then
# clear
cat $TMP_LIST.BBL_MENU|while read LINE
do
BBL_PID=`echo $LINE|awk '{print $1}'`
BBL_OWNER=`echo $LINE|awk '{print $2}'`
DOMAIN_ID=`echo $LINE|awk '{print $3}'`
Domain_Details
done
else
# clear
Domain_Details
fi
echo
echo "Press [RETURN/ENTER KEY] to continue."
read PAUSE
done
################################################################################
# End
################################################################################

Robert G. Jordan

Robert@JORDAN2000.com
Unix Admin, United Airlines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top