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

Re: [K12OSN] Checking for Group Membership



On Thu, 30 Jan 2003, Steve Wright wrote:

>here's a little script to which you can add whatever you like.  Just 
>paste it into your editor, save, and `chmod 700 test.sh`
>
>/steve
>
>
>#!/bin/bash
>#
># This script takes two arguments in the form
># ./test.sh <username> <group>
>
>user=$1
>group=$2
>
>
>#  is $user a member of $group ?
>
>if (grep $group /etc/group | grep $user) >>/dev/null  ; then
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A more flexible way of writting that line is:

	if (groups $user | grep $group) >>/dev/null ; then


These days you can't make the assumption that there is a complete
/etc/groups, /etc/passwd, etc ;-)

If you use the "id" command ("groups" is just a wrapper around "id"),
it will work with accounts stored in LDAP, NT domains, etc.

-Eric





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