Archive for December, 2009

Webpshere restart checker

A simple script to check if the websphere process is stopped or was restarted

#!/bin/ksh
##############################################################################
# Description – Check WebSphere Application Server
#
# This script checks the WebSphere process if its stopped/restarted recently
# Sanoop Kuniel (16-12-09)
#############################################################################

## Set Profile and Server instance to monitor ##
set -A profiles “AppSrv01″ “AppSrv02″
set -A servers “server1″ “server2″

notify_list=”sanoop_kuniel@aviva-asia.com”

i=0
while [ $i -lt ${#profiles[@]} ]
do

profile=${profiles[$i]}
server=${servers[$i]}
old_processid=”"

(( i=i+1 ))

result_file=”/tmp/CheckWAS.$profile.$server.result”

echo “##Script Start##” > $result_file
date >> $result_file
count_file=”/tmp/CheckWAS.$profile.$server.count”

## Check if we can find the last recorded process id if not assume first run os script
if [ -f $count_file ]
then
old_processid=`cat $count_file|cut -c 1-8`
echo “Found last recorded process id : $old_processid” >> $result_file
fi

echo “Hostname :: ” `hostname` >> $result_file
ps -ef|grep $profile|grep $server|grep -v grep|awk ‘{print $2}’>$count_file
was_count=`wc -l $count_file |cut -c 1-8`

echo “Profile :: $profile” >> $result_file
echo “Instance :: $server” >> $result_file

if [ $was_count = 0 ]
then
echo “!!!!!!!!! WebSphere Application Server is not running !!!!!!!!!” >> $result_file
mail -s “WEBSPHERE STOPPED on `hostname` – $profile – $server” “$notify_list”< $result_file
else
processid=`cat $count_file|cut -c 1-8`
if [ -z "$old_processid" ]
then
old_processid=$processid
fi
last_processid=`cat /usr/IBM/WebSphere/AppServer/profiles/$profile/logs/$server/$server.pid`

## Compare all process ids
if [ "$old_processid" != "$processid" ] || [ "$processid" != "$last_processid" ] || [ "$old_processid" != "$last_processid" ]
then
echo "Server was restarted!!" >> $result_file
echo “Last recorded process id :: $old_processid” >> $result_file
echo “Process id in pid file :: $last_processid” >> $result_file
echo “Current process id :: $processid” >> $result_file
mail -s “WEBSPHERE RESTART on `hostname` – $profile – $server” “$notify_list”< $result_file
echo "##Script End##" >> $result_file
exit 1
fi
echo “Process id :: `cat $count_file`” >> $result_file
echo “WebSphere is running…exiting” >> $result_file
fi
echo “##Script End##” >> $result_file
done