SUMMARY: Need Help with Shell Script

From: Bhavesh Shah <bshah_at_citadon.com>
Date: Wed Aug 17 2005 - 19:23:11 EDT
Many Thanks to Eugene and Brewer for their kind help with the script.
Their suggetions worked well.

Answer(s):

Eugene
--------

#!/usr/bin/sh
#List of app servers
APPSERVERS="192.168.0.1   192.168.0.3   192.168.0.100"

# Capture my current "SomeProcDESCRIPTION" processes PID PID=`pgrep
SomeProcDESCRIPTION`

# Set my PATH explicilty to avoid environmental poisoning and keep #
auditors happy PATH=/usr/bin:/usr/local/bin export PATH

# I save the last PID on shared storage, /u1/control/ in this case # as
example. # If I switch, proc is dead & the area also moves and
disappears off # the inactive node, as such nothing is done.


if [ -f /u1/control/monitor.app.pid ]; then
	# If proc does exist and is not null - first time
	if [ ! -z "${PID} ]; then
		echo $PID > /u1/control/monitor.app.pid
	fi

	OPID=`cat /u1/control/monitor.app.pid`

	if [ "${OPID}" != "${PID}" ]; then
		for APP in ${APPSERVERS}
		do
			ssh $APP "/etc/init.d/appserver restart"
		done
		# CHanged so we update
		echo $PID > /u1/control/monitor.app.pid
	fi
fi

exit 0

Brewer
-------

Instead of executing a single command when you connect via SSH you
should execute a pre-positioned shell script that does three things:
1) determines the value of PRIOR_CW_PID which could be something like:
    PRIOR_CW_PID=`tail -1 /var/log/CW_PID.txt`

2)  determined the value of CURRENT_CW_PID which is as you have already
decided:
	CURRENT_CW_PID="ps -ef |grep $CW | grep -v grep | awk '{print
\$2}'"

3) compare the two to see if the value has changed.  If it has not, then
report that it has not, but if it has changed:

    echo "$PRIOR_CW_PID changed to $CURRENT_CW_PID at:" >>
/var/log/CW_PID.txt
    echo `date` >> /var/log/CW_PID.txt
    echo $CURRENT_CW_PID >> /var/log/CW_PID.txt

and then report that it has changed.

MY Question was:
-----------------
Hi Gurus,
I am in a process of writing a shell script which checks for Database
instance process PID (which is in VCS control and it may failover to
another VCS node but sometimes it doesn't failover at all) every 5 min
and if the PID is changed which means DB has restarted and I recycle App
Servers. However I need some help by which I can keep the previous PID
value in memory or in a file whichever is simpler and efficient and
compare with current one if they both matches then DB is OK else PID
changed and need to restart App Serves.

I need to incorporate a logic which keeps the previous value of PID for
ORA process and compare with the current value and checks if both
matches or not. If you have any better idea than this one are most
welcome.

Sample Code:

#! /bin/ksh
PNET=ora_pmon_pnet
CW=ora_pmon_mprod
PNET_HOST=db01
CW_HOST=db02
CW_PID=$(ssh pnetops@$CW_HOST "ps -ef |grep $CW | grep -v grep | awk
'{print \$2}'") echo "CW_PID = $CW_PID" if [ $? = 0 ] then echo "True"
else ssh pnetops@$PNET_HOST "ps -ef |grep $CW | grep -v grep"
  if [ $? = 0 ]
  then
  echo "$CW DB is running on $PNET_HOST needs recycling App Servers"
  else
  echo "$CW DB is DOWN..When it will be UP App Servers will be recycled"
  fi
Fi

Appreicate your valueable time and support.
I will summarize.
Regards
B
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Wed Aug 17 19:23:55 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:50 EST