You are not logged in.

#1 2008-09-04 22:04:47

jmrbcu
Member
From: Cuba
Registered: 2007-08-20
Posts: 112

bash and groups

A simple question: how to know in a bash script if an user belongs to certain group, let's say: operators?


--------------------------------
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.
Recuerda: El arca de Noe fue construida por aficionados, el titanic por profesionales
-----------------------------------------------------------------

Offline

#2 2008-09-04 22:22:22

Garns
Member
Registered: 2008-05-28
Posts: 239

Re: bash and groups

man bash wrote:

GROUPS An array variable containing the list of groups of which the current user is a member.  Assignments to GROUPS have no effect  and return an error status.  If GROUPS is unset, it loses its special properties, even if it is subsequently reset.

It contains the group numbers, not the names.

Offline

#3 2008-09-04 22:29:28

jmrbcu
Member
From: Cuba
Registered: 2007-08-20
Posts: 112

Re: bash and groups

actually, what I want is if an user is member of a group, do somethin, else, do something else


--------------------------------
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.
Recuerda: El arca de Noe fue construida por aficionados, el titanic por profesionales
-----------------------------------------------------------------

Offline

#4 2008-09-05 00:03:08

pete-the-meat
Member
From: Scotland
Registered: 2008-08-14
Posts: 26

Re: bash and groups

check the /etc/group file? a little long winded but the only way i can think of doing it, and it's probably better done in perl as well


That looks like a much better way of trying to do what I was trying to do than trying to do what I was trying to do...

Offline

#5 2008-09-05 00:44:22

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: bash and groups

$ groups USERNAME

example

$ groups root
root bin daemon sys adm disk wheel log

so...

$ groups root | grep -qi wheel
$ if [ $? = 0 ]; then echo "root is a member of wheel"; else echo "root is not a member of wheel"; fi
root is a member of wheel

"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

Board footer

Powered by FluxBB