Wednesday, August 24, 2011

How to find all users group info??? userwise group / groupwise user

#!/bin/ksh
for LOOP in $(cat /etc/passwd|cut -f1,4 -d':')
do
  USRNAM=$(echo ${LOOP} |cut -f1 -d':')
  GRPID=$(echo ${LOOP} |cut -f2 -d':')
  GRPNAM=$(cat /etc/group |grep ":${GRPID}:"|cut -f1 -d':')
  echo "User \"${USRNAM}\" belongs to \"${GRPNAM}\" group"
done

No comments:

Post a Comment