#!/bin/sh
PATH=/usr/bin:$PATH
EG_HOME=/opt/egurkha
export PATH EG_HOME
#code to get the list of pids of the zone in which agent is currently running. ie. for Solaris Zone machines
isZone=0
zonename=""
if [ -f "/sbin/zonename" ] || [ -f "/usr/bin/zonename" ]
then
	zonename=`zonename`
	isZone=1
fi
if [ $isZone -eq 1 ]
then
	pid_list=`ps -z $zonename -o pid,args | grep $1 | grep -v count_process | grep -v grep | grep $2 | wc -l`
	if [ $pid_list -eq 0 ]
	then
		pid_list=`ps -z $zonename -o pid,args | grep " /opt/egurkha/" | grep -v count_process | grep -v grep | grep $2 | wc -l`
	fi
	if [ $pid_list -eq 0 ]
	then
		if [ -f "/usr/ucb/whoami" ]
		then
			whoami=`/usr/ucb/whoami`
			pid_list=`/usr/ucb/ps -gauxwww | grep $1 | grep $whoami | grep -v grep | grep $2 | grep -v count_process | wc -l`
		fi
	fi
else 
	pid_list=`ps -aef -o pid,args | grep $1 | grep -v count_process | grep -v grep | grep $2 | wc -l`
	if [ $pid_list -eq 0 ]
	then
		if [ -f "/usr/ucb/ps" ]
		then
			pid_list=`/usr/ucb/ps -gauxwww | grep $1 | grep $2 | grep -v grep | grep -v count_process | wc -l`
		fi
	fi
fi

echo $pid_list
