#!/bin/ksh
#
#ident	"@(#)devidio.sh	1.3	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

LOCALDEV=
REMOTEDEV=
L_DEVLIST=
R_DEVLIST=
RHOST=$1
RUNPRDR=10
RUNPRDL=
RNUMDEV=
rmachine=$1
rhname=$2
rmvartmp=
rhvartmp=
p_rname=
lineno_pr=0
utildir=/opt/SUNWhcts/prgs

# functions
clean_up()
{
        if [ -f /tmp/devlist* ]
        then
                 rm -f /tmp/devlist*
        fi

}

### MAIN ###

# Trap signals
trap 'clean_up; exit' 17


# Analyzed the hostnames of remote machine and ppp_client

tr ',' '\n' </tmp/pclient  > /tmp/pclient.tmp
mv /tmp/pclient.tmp /tmp/pclient
rmachine=`cat /tmp/pclient`

tr ',' '\n' </tmp/rhnames  > /tmp/rhnames.tmp
mv /tmp/rhnames.tmp /tmp/rhnames
rhname=`cat /tmp/rhnames`

echo "$j" > /tmp/ppp_rhname
for i in $rmachine
do
        
        for j in $rhname
        do
                if [[ $j = $i ]]
                then
                        echo "$j" >> /tmp/ppp_rhname
                        rmvartmp=`cat /tmp/pclient | grep -v $i`
                        echo "$rmvartmp" > /tmp/pclient 
                        rhvartmp=`cat /tmp/rhnames | grep -v $j`
                        echo "$rhvartmp" > /tmp/rhnames 
                fi
        done
done

#to ping ppp clients
p_rname=`cat /tmp/ppp_rhname`
if [ -n "$p_rname" ]
then
        for k in $p_rname
        do
                /usr/sbin/ping $k
                if [ $? -ne 0 ]
                then
                        echo "!ERROR: Remote machine or ppp_client $k is unreachable."
                        exit 1
                fi
        done
fi

# get the devices' names that to be used to do test
p_rname=`cat /tmp/ppp_rhname`
if [ -n "$p_rname" ]
then
	for z in $p_rname
	do
		$utildir/devid.sh $z 
		mv /tmp/devlist.$z /tmp/devlist3.$z
		cat /tmp/devlist3.$z | sed -e 's/\//*/g' > /tmp/devtmp
		cp /tmp/devtmp /tmp/devlist3.$z
		rm /tmp/devtmp
		if [ -z `tail -1 /tmp/devlist3.$z` ]
		then
			echo "!ERROR:No devices to run serial IO test are detected on $z."
			exit 1
		else
			let lineno_pr=lineno_pr+1
		fi
	done
	echo $lineno_pr > /tmp/saip_linenopr
fi

