#!/bin/bash ## This script will find orphaned users in the system that don't ## belong to any groups. # Call awk to isolate username and group id awk -F ':' '{print $1, $4}' /etc/passwd | # Pass that data to the loop while read user gid ; # 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 ## By using awk, a bit of memory is saved because no unused variables ## are declared for the read command.