#!/bin/ksh

echo "IN:`date`: $*"
if [ "$1" = "FCPIO" ]
then 
	src=`echo $2|cut -f1 -d'|'`
	dst=`echo $2|cut -f2 -d'|'`
	echo "Source $src Destination $dst"
	cd $src
	find . -xdev -depth -print |fgrep -f $3 -v|cpio -ocB| (cd $dst; cpio -icdBum)
#	find . -xdev|egrep -f $3 -v|cpio -pvmd $dst
#	find . -xdev|egrep -f $3 -v
else
	if [ "$1" = "ICOPY" ]
	then
		src=`echo $2|cut -f1 -d'|'`
		dst=`echo $2|cut -f2 -d'|'`
		mdt=`echo $2|cut -f3 -d'|'`
		export MOVER_TARGET=$dst
		export MOVER_REFDATE=$mdt
		cd $src
#		find . -xdev |xargs -I {} get_file_mtime {}
# Modif pour ne pas passer tous les fichiers a la moulinette get_file_mtime
#
		find . -xdev -mtime -2 |xargs -I {} get_file_mtime {}
	else
		if [ "$1" = "SCHED" ]
		then
			echo "Scheduled plex"
			dg=`echo $2|cut -f1 -d'|'`
			vol=`echo $2|cut -f2 -d'|'`
			plex=`echo $2|cut -f3 -d'|'`
			>/tmp/sched_vxcopy.$$
			echo "PID=$$">>/tmp/sched_vxcopy.$$
			echo "vxplex -g $dg -o slow=1,iosize=4m $vol $plex >/tmp/vxout.$$" >>/tmp/sched_vxcopy.$$
			echo "status=$?"
			echo "echo ""Termination Code : $? "">/tmp/sched_vxout.$$ ">>/tmp/sched_vxcopy.$$
			chmod 700 /tmp/sched_vxcopy.$$
			at -t $3 -f /tmp/sched_vxcopy.$$
			while [ ! -f /tmp/sched_vxout.$$ ]
			do
				sleep 60 
			done
			echo "Script done"
		else
			if [ "$1" = "RSYNC" ]
			then
				rsync -av --rsync-path=/serveur/dp/bin/rsync --partial \
				--stats --delete --force $2 $3
				status=$?
				echo "Termination code : $status"
				
			else
				vxplex -g $1 -o slow=1,iosize=4m att $2 $3
				status=$?
				echo "Termination code : $status"
			fi
		fi
	fi
fi

echo "OUT:`date`: $*"
exit 0
