#! /usr/bin/ksh
#
#ident	"@(#)scp_6.sh	1.5	05/06/24 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# by Mark F. Logan
# Modified by Andrew McCarthy
# Modified by Bill Yan on Jan. 29th 2004

if [ $# -ne 1 ]
then
	echo "Usage: $0 dest-machine."
	exit 1
fi

echo "Runtime: $RUNTIME seconds."
sleep $RUNTIME &
sleepid=$!
warnings=0
iters=0
threshold=1

echo "Changing local directory to /tmp."
cd /tmp

local=`hostname`
version=`/usr/bin/uname -r|awk -F. '{print $2}'`

while [ -d /proc/$sleepid ]
do
	date
	if [ $version -lt 10 ]
	then
		rcp /kernel/genunix [$1]:/export/home/tmp/genunix.$local.$$
		rcp [$1]:/export/home/tmp/genunix.$local.$$ genunix.$$
		if cmp genunix.$$ /kernel/genunix
		then
			rm genunix.$$
			rcp /etc/motd [$1]:/export/home/tmp/genunix.$local.$$
		else
			warnings=$(($warnings+1))
		fi
	else
		scp /kernel/genunix [$1]:/export/home/tmp/genunix.$local.$$
		scp [$1]:/export/home/tmp/genunix.$local.$$ genunix.$$
		if cmp genunix.$$ /kernel/genunix
		then
			rm genunix.$$
			scp /etc/motd [$1]:/export/home/tmp/genunix.$local.$$
		else
			warnings=$(($warnings+1))
		fi
	fi
	iters=$(($iters+1))
	sleep 1
done

if [ $(($warnings*1000/$iters)) -le $(($threshold*10)) ]
then
	echo "!PASS: Completed $iter copies successfully on IPv6."
else
	echo "!ERROR: scp_6 failed."
fi
