Re: [CentOS] Shell script to list group members

2008-09-24 Thread Ian Blackwell
Bob Beers wrote: grep group_name: /etc/group | cut -d: -f4 will give a comma separated list, provided group_name is a valid group name. There is one problem with this approach, which is the assumption that all users' primary group is the same as their login id - which I agree is typically

Re: [CentOS] Shell script to list group members

2008-09-24 Thread Bob Beers
Part 1: On Tue, Sep 23, 2008 at 7:37 PM, Ian Blackwell [EMAIL PROTECTED] wrote: Bob Beers wrote: grep group_name: /etc/group | cut -d: -f4 will give a comma separated list, provided group_name is a valid group name. There is one problem with this approach, which is the assumption that

Re: [CentOS] Shell script to list group members

2008-09-24 Thread Ian Blackwell
Bob Beers wrote: Part 1: You have a valid point, but the OP's question was: 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. In all likelihood the system follows the default approach of

[CentOS] Shell script to list group members

2008-09-23 Thread Tim Alberts
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

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Barry Brimer
Quoting Tim Alberts [EMAIL PROTECTED]: 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

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Bob Beers
On Tue, Sep 23, 2008 at 1:31 PM, Tim Alberts [EMAIL PROTECTED] 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:

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Tim Alberts
Barry Brimer wrote: 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 }' I'm sorry, I didn't specify, I'm using LDAP for user/group management.

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Bob Beers
On Tue, Sep 23, 2008 at 7:11 PM, Tim Alberts [EMAIL PROTECTED] wrote: Barry Brimer wrote: 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

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Barry Brimer
Quoting Tim Alberts [EMAIL PROTECTED]: Barry Brimer wrote: 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 }' I'm sorry, I didn't

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Bob Beers
On Tue, Sep 23, 2008 at 7:26 PM, Barry Brimer [EMAIL PROTECTED] wrote: Quoting Tim Alberts [EMAIL PROTECTED]: Barry Brimer wrote: With spaces separating groups: egrep -e '^groupname:' /etc/group | awk -F : '{ print $4 }' | sed -e 's/,/ /g' With commas separating groups: egrep -e

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Tim Alberts
Bob Beers wrote: On Tue, Sep 23, 2008 at 7:26 PM, Barry Brimer [EMAIL PROTECTED] wrote: With commas separating groups: getent group | egrep -i '^groupname:' | awk -F : '{ print $4}' With spaces separating groups: getent group | egrep -i '^groupname:' | awk -F : '{ print $4}' | sed -e

Re: [CentOS] Shell script to list group members

2008-09-23 Thread Barry Brimer
On Tue, 23 Sep 2008, Bob Beers wrote: On Tue, Sep 23, 2008 at 7:26 PM, Barry Brimer [EMAIL PROTECTED] wrote: Quoting Tim Alberts [EMAIL PROTECTED]: Barry Brimer wrote: With spaces separating groups: egrep -e '^groupname:' /etc/group | awk -F : '{ print $4 }' | sed -e 's/,/ /g' With

Re: [CentOS] Shell script to list group members

2008-09-23 Thread MHR
On Tue, Sep 23, 2008 at 6:43 PM, Barry Brimer [EMAIL PROTECTED] wrote: The egrep is using a leading anchor (^) to make sure the grep matches the beginning of the line. If not, and the group pattern matched as one of the users it would print those lines too .. which is probably undesirable.