#!/bin/sh

#  The following is the format of the parameters
#  1.<User parameters> (Anything that the user gives during test configuration will be here)
#  2. -info (constant)
#  3. <the value of the info>
#  We get all the parameters that the test gets
#  4. -host (constant)
#  5. <the monitored target, this could be IP or nick)
#  6. -port (constant)
#  7. <port number of the monitored target, if any>
#  8. -process (constant)
#  9. <whatever is configured for process>
#  10 -user (constant)
#  11 <user name>
#  12 -rptName (constant)
#  13 <the rpt name>
#  14 -correct 
#  15 true (This will always be true, otherwise we wouldn't have come here)
#  16 -egMeasHost (constant)
#  17 <the measurement host>
#  18 -site (constant) 
#  19 <site name>
#  20 -egMeasVals (constant) 
#  The actual measures and the state follows
#  For process test, the following are the measures and state
#  21 -Num_procs_running (measure name, constant)
#  22 <state>
#  23 -Cpu_util 
#  24 <state>
#  25 -Memory_util
#  26 <state>

process=$1
info=$3

while :
do
	s=`echo "$process" | cut -d "," -f1`
	i=`echo "$s" | cut -d ":" -f1`
    if [ "$i" = "$info" ] || [ "$i" = "$s" ]
    then
        cmd=`echo "$s" | cut -d ":" -f2`
        echo "Executing: $cmd"
        $cmd
        exit;
    fi

	len=`expr length "$s"`
	len=`expr $len + 2`
	fullLen=`expr length "$process"`
	s=`expr substr "$process" $len $fullLen`
	process=$s
	len=`expr length "$process"`
	if [ $len -eq 0 ]
	then
		exit;
	fi
done

