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
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.