Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i check if unix group exists 1

Status
Not open for further replies.

philipose

Programmer
Dec 24, 2003
137
US
Hi,
I was using a branch logic in a shell script. If a particular Unix Group exists then do this else do something else.

Is there a way for me to check if a Unix group exists or not ?

Thanks
philipose
 
sth like this?

[tt]lsgroup -a id ${GROUP} 2>/dev/null && echo group ${GROUP} exists

lsgroup -a id ${GROUP} 2>/dev/null || echo group ${GROUP} does not exist

if lsgroup -a id ${GROUP} 2>/dev/null
then
echo group ${GROUP} exists
else
echo group ${GROUP} does not exist
fi[/tt]


HTH,

p5wizard
 
Here is something a little more generic:

#!/bin/ksh

mygroup=xsys
myb=1
while IFS=":" read GROUP other
do
if [ $GROUP = $mygroup ]
then
myb=0
break
fi
done < /etc/group && (( $myb == 0 )) && echo "$mygroup exists"
 
Well, this IS an AIX forum so I gave an AIX answer... ;-)


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top