home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10836 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.1 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!gatech!concert!sas!mozart.unx.sas.com!sasmob
  2. From: sasmob@chewy.unx.sas.com (Mark C. Burhans)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: I want a program that prints out base gid's of any user
  5. Message-ID: <BuA2qB.oI@unx.sas.com>
  6. Date: 8 Sep 92 21:08:35 GMT
  7. References: <BtIqyp.F5A@news.cso.uiuc.edu> <1992Aug25.134646.9039@news.eng.convex.com>
  8. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  9. Organization: SAS Institute Inc.
  10. Lines: 49
  11. Originator: sasmob@chewy.unx.sas.com
  12. Nntp-Posting-Host: chewy.unx.sas.com
  13.  
  14.  
  15. In article <1992Aug25.134646.9039@news.eng.convex.com>, Tom Christiansen <tchrist@convex.COM> writes:
  16. |> From the keyboard of bzg52408@uxa.cso.uiuc.edu (Benjamin Z. Goldsteen):
  17. |> :   I have been trying to write a program that prints out the
  18. |> :base gid of a user (given on the command line).  I have tried
  19. |> :using awk and perl, but I can not get anything decent.
  20. |> :Can show me how to do this.  One thing I have tried
  21. |> :[ gid username ]
  22. |> :#! /usr/bin/awk -f
  23. |> :BEGIN { FS=":"; FILENAME="/etc/passwd" }
  24. |> :ARGV[1] == $1 {print $4}
  25. |> :
  26. |> :I am not sure if 1 if right for ARGV, but whatever...anyway, it 
  27. |> :won't read from /etc/passwd - it only reads from stdin.  I can;t
  28. |> :make it do otherwise.
  29. |> :
  30. |> :I don't really understand perl...
  31.  
  32. Since everybody else posted a perl script or something besides 'awk', I
  33. thought I'd contribute with an 'awk' answer:
  34.  
  35. ---cut here-------------------------
  36. #!/bin/ksh
  37.  
  38. awk -F: -v LOGIN=$1 'BEGIN { NOTFOUND = 1 }
  39. {
  40.     if( $1 == LOGIN )
  41.     {
  42.         print LOGIN " belongs to group number: "$4
  43.         system( "groups -p $1" )
  44.         NOTFOUND = 0
  45.         exit
  46.     }
  47. }
  48. END { if( NOTFOUND ) print "Cannot locate user: " LOGIN }' </etc/passwd    
  49. -----cut here----------------------
  50.  
  51. Let's say this was the name of the file 'gid'.  Syntax would be:
  52.  
  53. gid UserLoginId
  54.  
  55.  
  56.  
  57. -- 
  58. ---Mark C. Burhans---sasmob@chewy.unx.sas.com---919/677-8001 ext 7324
  59. SAS Institute, Inc., USA, SAS Campus Drive, Cary, NC 27513.
  60. "If you want a resume, I'll put it in writing.  It's only good for a day
  61. and the contents are frightening."  -- Lyrics by Harry Connick, Jr.
  62.  
  63.