home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!gatech!concert!sas!mozart.unx.sas.com!sasmob
- From: sasmob@chewy.unx.sas.com (Mark C. Burhans)
- Newsgroups: comp.unix.questions
- Subject: Re: I want a program that prints out base gid's of any user
- Message-ID: <BuA2qB.oI@unx.sas.com>
- Date: 8 Sep 92 21:08:35 GMT
- References: <BtIqyp.F5A@news.cso.uiuc.edu> <1992Aug25.134646.9039@news.eng.convex.com>
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Organization: SAS Institute Inc.
- Lines: 49
- Originator: sasmob@chewy.unx.sas.com
- Nntp-Posting-Host: chewy.unx.sas.com
-
-
- In article <1992Aug25.134646.9039@news.eng.convex.com>, Tom Christiansen <tchrist@convex.COM> writes:
- |> From the keyboard of bzg52408@uxa.cso.uiuc.edu (Benjamin Z. Goldsteen):
- |> : I have been trying to write a program that prints out the
- |> :base gid of a user (given on the command line). I have tried
- |> :using awk and perl, but I can not get anything decent.
- |> :Can show me how to do this. One thing I have tried
- |> :[ gid username ]
- |> :#! /usr/bin/awk -f
- |> :BEGIN { FS=":"; FILENAME="/etc/passwd" }
- |> :ARGV[1] == $1 {print $4}
- |> :
- |> :I am not sure if 1 if right for ARGV, but whatever...anyway, it
- |> :won't read from /etc/passwd - it only reads from stdin. I can;t
- |> :make it do otherwise.
- |> :
- |> :I don't really understand perl...
-
- Since everybody else posted a perl script or something besides 'awk', I
- thought I'd contribute with an 'awk' answer:
-
- ---cut here-------------------------
- #!/bin/ksh
-
- awk -F: -v LOGIN=$1 'BEGIN { NOTFOUND = 1 }
- {
- if( $1 == LOGIN )
- {
- print LOGIN " belongs to group number: "$4
- system( "groups -p $1" )
- NOTFOUND = 0
- exit
- }
- }
- END { if( NOTFOUND ) print "Cannot locate user: " LOGIN }' </etc/passwd
- -----cut here----------------------
-
- Let's say this was the name of the file 'gid'. Syntax would be:
-
- gid UserLoginId
-
-
-
- --
- ---Mark C. Burhans---sasmob@chewy.unx.sas.com---919/677-8001 ext 7324
- SAS Institute, Inc., USA, SAS Campus Drive, Cary, NC 27513.
- "If you want a resume, I'll put it in writing. It's only good for a day
- and the contents are frightening." -- Lyrics by Harry Connick, Jr.
-
-