Path: utzoo!utgpu!cunews!mitel!lalonde From: lalonde@mitel ( iccad) Newsgroups: comp.lang.perl Subject: SOURCE: lg -list groups Summary: perl source: list system groups Keywords: group Message-ID: <6918@mitel> Date: 14 Mar 91 03:38:02 GMT Distribution: comp Organization: MITEL Corporation, Kanata, Ontario, Canada. Lines: 68 I wrote and installed this while ago. Either no one uses it or it works as advertised. Your comments/critiques are welcome. NAME lg - list groups; diplays users in specified groups or lists existing groups SYNOPSIS lg [ groupname ] DESCRIPTION lg with no argument or an argument which specifies a non- existant group will list the existing groups. When given an argument describing a valid group the users in that group are listed. Report bugs to lalonde@mitel.com #!/usr/bin/perl $, = ','; # set output field separator $\ = "\n"; # set output record separator { if( $#ARGV lt 0 ) { while(@rec = getgrent) { push(@t, @rec[0]); } undef %mark; grep($mark{$_}++,@t); @t = sort keys %mark; undef %mark; printf "There are %s groups:\n",$#t; print @t; } else { @rec = getgrnam($ARGV[0]); if($#rec >= 0) { @t = split(/[ ]+/,@rec[3]); while(@pass = getpwent) { if( @pass[3] eq @rec[2] ) { push(@t, @pass[0]); } undef %mark; grep($mark{$_}++,@t); @t = sort keys %mark; undef %mark; } printf "The %d member(s) of group (%s) \"%s\" are: \n", $#t+1,@rec[2],@rec[0]; # If I was a real perl programmer I'd use a "format" wouldn't I? for( $j=0; $j <= $#t; $j+=6) { printf "%-8s %-8s %-8s %-8s %-8s %-8s\n",@t[$j],@t[$j+1],@t[$j+2],@t[$j+3],@t[$j+4],@t[$j+5];} } else { printf "No such group as \"%s\"\n",$ARGV[0]; exec $0; } } } -- ============================================================================== Terry Lalonde (613)592-2122 | "the war between mainframes and micros is over Usenet:...!uunet!mitel!lalonde| over and the network has won" Internet: lalonde@mitel.com | Editors Network Computing 01/91