home vs user

Hello,

I am trying to find out all users who still have a home dir but do not exist anymore in /etc/passwd file. Here is what I did but I am getting the opposit of what I want. Any suggestion?

for USAGERD in `find /home -type d -exec ls -d {} \;`
do
USAGER=${USAGERD##/*/}
USAGERT=${USAGERD##/*/}
        USAGER=$(cat /etc/passwd | grep ${USAGER})
                if [[ -n ${USAGER} ]]
                then
                    echo $USAGERT
                fi
done

something like..

LIST=`grep home /etc/passwd | cut -d':' -f6 | cut -d/ -f3`
for I in `ls /home`; do
  echo $LIST | grep -q $I
  [ $? -eq 0 ] || ([ -d /home/$I ] && echo /home/$I )
done

not tested..

Tks, but that is giving me exactlly the same as my script, I am looking for all home dir that do not have a user in /etc/passwd

But that's exactly what the script produces, all dirs in .home that do not have an entry in /etc/passwd. I've tested it now :slight_smile:

Hi, maybe try another approach:

ls -1 /home|while read hd;do 
egrep ^$hd: /etc/passwd > /dev/null || echo Homedir $hd has no user
done

to me that reads: For each directory in /home, check if there is a corresponding line in /etc/passwd that starts with that directory name plus a colon.

/Lakris