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

Re: [K12OSN] Checking for Group Membership



Larry Mateo wrote:

Red Hat Linux release 7.3

Kernal: 2.4.18-3smp



I'm developing and modifying various script files. I have the need to determine if a user is a member of a specific group, and then do some action(s) based upon the outcome.



How would I do this with an "if...then" test or "case" statement, or is there some other clever way?



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



echo yes;

# other stuff to do goes here.



else

echo no ;

# more commands to do if answer is no.



fi






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