As has been said, we don't normally answer programming questions here, but this sounded like a fun five minute exercise.
This is offered to you without any indication that it works as you expect because my system always creates the users home, and no, I am not about to start playing around and messing up the passwd file to test this for you. So, run this in a text box first, or comment out the bits that do anything (mkdir and chown) and put in some echo commands.
All normal caveats apply: no support is offered or implied; the cheques in the post; and my favourite - its fix in the next release.
#!/bin/bash
# Check if users home directory exists
while read -r LINE; do
userID=echo $LINE | awk -F: '{print $3}'
if [ "$userID" -ge "1000" -a "$userID" -lt "65534" ] ; then
userName=echo $LINE | awk -F: '{print $1}'
userHome=echo $LINE | awk -F: '{print $6}'
userGroup=echo $LINE | awk -F: '{print $4}'
if [ ! -d "$userHome" ]; then
echo found user $userID $userName is missing home: $userHome
mkdir $userHome
chown $userName:$userGroup $userHome
fi
fi
done < /etc/passwd
Check if users home directory exists
while read -r LINE; do
userID=echo $LINE | awk -F: '{print $3}'
if [ "$userID" -ge "1000" -a "$userID" -lt "65534" ] ; then
userName=echo $LINE | awk -F: '{print $1}'
userHome=echo $LINE | awk -F: '{print $6}'
userGroup=echo $LINE | awk -F: '{print $4}'
if [ ! -d "$userHome" ]; then
echo found user $userID $userName is missing home: $userHome
mkdir $userHome
chown $userName:$userGroup $userHome
fi
fi
done < /etc/passwd
Do be careful - you can do a lot of damage to your system running any sort of file as root (which this will need). TEST TEST AND TEST AGAIN.