#!/bin/bash

## This script will find orphaned users in the system that don't
## belong to any groups.

# Parse the passwd file first, preventing an infinite loop if used
# with the form while IFS=: read gid < /etc/passwd.
cat /etc/passwd |

# IFS is a system preset field delimiter variable
# This "reads" each field in the passwd file separated by the ":"
# and assigns them to a variable. The one we want is $gid.
while IFS=: read user passwd uid gid name path shell ;

	# Loop to compare EACH $gid to the entire /etc/group file at
	# once
do
	if grep $gid /etc/group > /dev/null ; # silences grep
	then continue ; # if found, take no action
	else echo "$user does not belong to any known group" ;
	fi
done 

