#! /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

if [ ! -d $BCNUHOME/clients ]
        then
                mkdir $BCNUHOME/clients
fi

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

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

for client in $BCNULOADED
do

	echo "Client: $client"

case "$1" in

send)


		if $BCNU -a send -f $BCNUHOME/clients/agents.$client -n /etc/agents $client 
			then
				echo "Send OK"
		else
				echo "Send Failed"
		fi
		if $BCNU -a reload $client
                	then
                        	echo "OK - Client reloaded"
	        else
        	                echo "Failed to reload client"
	        fi
	;;
get|*)


		if $BCNU -a get -f /etc/agents >$BCNUHOME/clients/agents.$client $client 
			then
				echo "Get OK"
		else
				echo "Get Failed"
		fi
	;;

esac
echo "$client $1 complete"
done
