#!/bin/ksh
#
#  Shell script to files that belong to a named group to a new named group.
#  Searches down the directory tree from current directory and changes all 
#  files that belong to the named group only.
#  You must have permission to change the group of the files and the
#  new group must exist !!!
#
#  John Roebuck - 15/01/99
#

if [ $# != 2 ]
   then echo "Usage : ch-grp oldgroup newgroup"
        exit
fi

oldgroup=$1
newgroup=$2
tmpfile=/tmp/change-group$$$$

find ./ -group $oldgroup > $tmpfile

{
while read files
do

	oldgrp=`ls -l $files | awk '{ print $4 } '`
	chgrp $newgroup $files  2> /dev/null 1> /dev/null
	if [ $? -ne 0 ] 
	   then echo "Error changing group of "$files
	   else newgrp=`ls -l $files | awk '{ print $4 } '`
	        echo $files" has been changed from " $oldgrp " to " $newgrp
	fi

done } < $tmpfile

rm $tmpfile
