SUMMARY: Need Help with Shell Script

From: Bhavesh Shah <>
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.



#List of app servers

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

# 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/ ]; then
	# If proc does exist and is not null - first time
	if [ ! -z "${PID} ]; then
		echo $PID > /u1/control/

	OPID=`cat /u1/control/`

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

exit 0


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
	CURRENT_CW_PID="ps -ef |grep $CW | grep -v grep | awk '{print

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:" >>
    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

Sample Code:

#! /bin/ksh
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 ]
  echo "$CW DB is running on $PNET_HOST needs recycling App Servers"
  echo "$CW DB is DOWN..When it will be UP App Servers will be recycled"

Appreicate your valueable time and support.
I will summarize.
sunmanagers mailing list
sunmanagers mailing list
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