#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    56
    Rep Power
    4

    Identify Users On My Server


    I've got a Linux server with ~200 user accounts on it. At one point accounts were genricly being created and their primary group (GID) was "users". Since I've taken over, I've created appropriate groups for users but my question is, how can I create a file w/ all the users on the system in /etc/passwd who have a primary GID of "users"?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,485
    Rep Power
    1752
    If their primary GID is users, then the relevant, colon-delimited field in /etc/passwd will contain that number.
    If the GID for users is, say, 20 then ...
    Code:
    awk -F\: '$4 == 20 {print $1} /etc/passwd'
    should provide what you are after, you can then redirect the output to a file of your choosing.
    Last edited by SimonJM; December 20th, 2011 at 12:34 PM. Reason: To correct sytnax!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,485
    Rep Power
    1752
    If you are not sure what the GID is, you could try:

    Code:
    awk -F\: -v gid=$(awk -F\: '$1 == "users" print $3' /etc/group)  '$4 == gid {print $1} /etc/passwd'
    Which will set an awk user variable (the -v gid= ... bit) to the value of the GID of the specifed group name (here it is users) in the /etc/group file. That value is then used for the GID comparison in the (original) awk.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo