I have several shell scripts to manage user accounts on a server. I've been using a file with the usernames of peoples accounts that any script needs to process. I had a thought that I can and should be setting up groups and adding user accounts to those groups so I don't have to maintain a set of files with the user accounts. So essentially, I am looking for a (simple) shell command to run from a bash script that will allow me to list user accounts that belong to a particular group. Any help is appreciated. -------------- next part -------------- A non-text attachment was scrubbed... Name: talberts.vcf Type: text/x-vcard Size: 337 bytes Desc: not available URL: <http://lists.centos.org/pipermail/centos/attachments/20080923/3c1c7252/attachment-0001.vcf>
Quoting Tim Alberts <talberts at msiscales.com>:> I have several shell scripts to manage user accounts on a server. I've > been using a file with the usernames of peoples accounts that any script > needs to process. I had a thought that I can and should be setting up > groups and adding user accounts to those groups so I don't have to > maintain a set of files with the user accounts. > > So essentially, I am looking for a (simple) shell command to run from a > bash script that will allow me to list user accounts that belong to a > particular group. Any help is appreciated.With spaces separating groups: egrep -e '^groupname:' /etc/group | awk -F : '{ print $4 }' | sed -e 's/,/ /g' With commas separating groups: egrep -e '^groupname:' /etc/group | awk -F : '{ print $4 }'
On Tue, Sep 23, 2008 at 1:31 PM, Tim Alberts <talberts at msiscales.com> wrote:> So essentially, I am looking for a (simple) shell command to run from a bash > script that will allow me to list user accounts that belong to a particular > group. Any help is appreciated.grep <group_name>: /etc/group | cut -d: -f4 will give a comma separated list, provided <group_name> is a valid group name. HTH, -Bob