#! /bin/sh
if [ -d /usr/local/bcnu ]
then
        BCNUHOME="/usr/local/bcnu"
else
	echo "Enter directory name of bcnu home:[/usr/local/bcnu] \c"
	read home
	if [ -z "$home" ]
		then
			BCNUHOME="/usr/local/bcnu"
		else
		BCNUHOME=$home
	fi
fi

cd $BCNUHOME

. $BCNUHOME/etc/bcnuenv

echo "Please wait.."
LOAD=$1
BCNULOADED=${LOAD:=`$BCNUHOME/scripts/get_hosts managed | grep -v $BCNUHOST`}

BCNU="$BCNUHOME/bin/bcnu -s $BCNUPORT"

echo "Enter files to be sent - space delimited $BCNUHOME/\c"
	read tobesent
	if [ -z "$tobesent" ]
		then
			echo "Files required - send aborted"
			exit
	fi

BCNUSEND=`cd $BCNUHOME; ls $tobesent`
echo $BCNUSEND
	for sendfile in $BCNUSEND
	do
		if [ ! -r $BCNUHOME/$sendfile ]
			then
				echo "Error: $BCNUHOME/$sendfile is unreadable or does not exist"
				exit
		fi
	done

echo "Files to be sent: $BCNUSEND"

for client in $BCNULOADED
do

	echo "Client: $client"

	for sendfile in $BCNUSEND
	do
		echo "\tSending $sendfile to $client:\t\c"

		if $BCNU -a send -f $BCNUHOME/$sendfile -n /$sendfile $client 
			then
				echo "OK"
		else
				echo "Failed"
		fi
	done
echo "$client sends complete"
done
