[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How do I list all users in a group?



Am 2007-03-07 05:59:38, schrieb kawanokami:
> sorry... I should have mentioned that I looked into that too. It
> doesn't seem to list the group owner... I mean: group www-data doesn't

A GROUP does not have an owner.

> contain user www-data and so I end up not knowing if a specified group

The USER "www-data" is a member of the GROUP "www-data".

> is "owned" by someone.

If I do a 

    egrep ".*:.*:.*:1000:" /etc/passwd |cut -d ':' -f1

I get

michelle.konzack
tamay.dogan
michiar
michitr
dummy.user

and now tell me WHO is the owner.

I use since some years a small function which I load from my bashrc
because I have nothing found since Potato:

----8<-----------------------------------------------------------------
fnc_show_groupmembers()
{
  local OPT="$1"
  local GRP="$2"
  if [ "${OPT}" = "-h" ] || [ "${OPT}" = "--help" ] || [ -z "${OPT}" ] ; then
    echo "Usage:    fnc_show_groupmembers [ -h | --help | -p | -g | -a ] <group>"
    echo
    echo "    -h  Show this help and exit"
    echo "    -p  Show standard members from /etc/passwd."
    echo "    -g  Show additional members from /etc/group."
    echo "    -a  Show all members."
  else
    local GRP_STR=$(grep "^${GRP}:" /etc/group)
    if [ -n "${GRP_STR}" ] ; then
      local GRP_G=$(echo  "${GRP_STR}" |cut -d':' -f4)
      local GRP_ID=$(echo "${GRP_STR}" |cut -d':' -f3)
      local GRP_P=$(egrep ".*:.*:.*:${GRP_ID}:" /etc/passwd |cut -d':' -f1)
      if   [ "${OPT}" = "-p" ] && [ -n "${GRP_P}" ] ; then
        echo "${GRP_P}" |tr '\n' ' ' |tr -s ' '
        echo
      elif [ "${OPT}" = "-g" ] && [ -n "${GRP_G}" ] ; then
        echo "${GRP_G}" |tr '\n' ' ' |tr -s ' '
        echo
      elif [ "${OPT}" = "-a" ] && [ -n "${GRP_P}" ] && [ -n "${GRP_G}" ] ; then
        echo "${GRP_P} ${GRP_G}" |tr '\n' ' ' |tr -s ' '
        echo
      fi
    fi
  fi
}
----8<-----------------------------------------------------------------

Greetings and nice Day
    Michelle Konzack
    Systemadministrator
    Tamay Dogan Network
    Debian GNU/Linux Consultant


-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSN LinuxMichi
0033/6/61925193    67100 Strasbourg/France   IRC #Debian (irc.icq.com)

Attachment: signature.pgp
Description: Digital signature


Reply to: