#!/bin/ksh

starttime=0
endtime=0
ldev=
HDS_BIN=$1
sleepid=$2



# test level
tlevel=$(cat /tmp/level.dat)

# device list
dls=$(cat /etc/mnttab | grep -v ":boot" | grep -w "/dev/dsk" | \
grep "rw," | tr ":" "-" | sort -k 1.1)



# access method
am=
[ "$tlevel" = L1 ] && am="method=AsyncIO" 

#check dls
if [ -z "$dls" ]
then
	echo "No Hard drives found."
	exit 1
fi


while [ -d /proc/$sleepid ]
do

	pid=$(/usr/bin/pgrep disktest)


	if [ -z "$pid" ]
	then
		#echo "*** STOP TIMER  IF IT'S RUNNING ***\n"

		if [ $starttime -gt 0 ]; then
			endtime=`../../prgs/time_sec`
			ltime=`expr $endtime - $starttime`
			if [ $ltime -gt 300 ]
			then
				echo LOOPTIME: $ltime
			fi
		fi
	
		# Reset variable
		ldev=		
		# get device list
		echo "$dls" | while read inline
		do
			dev=$(echo $inline | awk -F"/" '{print $4}' | cut -f1 -d's')
			if [ "$dev" != "$ldev" ]
			then
				hds/bin/$HDS_BIN/disktest -v -o dev=$dev,$am &
				jobid=$!
				sleep 1
				if [ ! -d /proc/$jobid ]; then
					echo "!ERROR Starting $dev"
				exit 1
				fi
			fi
			ldev=$dev
		done
			
		starttime=`../../prgs/time_sec`
	fi
done	
	
