FindFilesOwnedByOthers.ksh

#!/bin/ksh

# FindFilesOwnedByOthers.ksh

# Searches the home dirs of a predined
# list of users for files that they don't own.

# - Jim

# Read one line at a time into USER.
IFS="
"

# Get a user.
for USER in $(cat /tmp/Users.txt); do

 echo "EXAMINING USER: 	$USER"

 # Find the user's home dir.
 if [[ -n "$(grep ^$USER: /etc/passwd | grep home)" ]]; then

   # Go to the user's home dir.
   cd $(grep $USER /etc/passwd | cut -d: -f6) 2>/dev/null

   # Did we get into the user's directory?
   if [[ "$?" = "0" ]]; then
     # The user directory exists.
     # Do your work in it.
     echo "WE ARE IN DIRECTORY $PWD."
     echo "LISTING FILES/DIRECTORIES NOT OWNED BY USER: $USER."

     # List all the files owned by the user.
     for FILE in $(find . -ls)
     do
       # Find out if the file is owned by the user.
       echo " $FILE" | tr -s " " "" | cut -d" " -f6- | grep -v ^"$USER"
     done

   fi
 fi
done 
exit