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

if [ $# != 2 ]
   then echo "Usage : chg-own oldowner newowner"
        exit
fi

oldowner=$1
newowner=$2
tmpfile=/tmp/change-owner$$$$

find ./ -user $oldowner > $tmpfile

{
while read files
do

	oldown=`ls -l $files | awk '{ print $3 } '`
	chown $newowner $files  2> /dev/null 1> /dev/null
	if [ $? -ne 0 ] 
	   then echo "Error changing ownership of "$files
	   else newown=`ls -l $files | awk '{ print $3 } '`
	        echo $files" has been changed from " $oldown " to " $newown
	fi

done } < $tmpfile

rm $tmpfile
