Added groupcount.
This commit is contained in:
parent
32dd4a8f0e
commit
153a63a73b
|
@ -3,7 +3,7 @@ include GNUmakevars
|
||||||
CONFDIR=../../configure
|
CONFDIR=../../configure
|
||||||
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
|
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
|
||||||
|
|
||||||
all: configure grouplist groupmatch
|
all: configure grouplist groupmatch groupcount
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm grouplist groupmatch
|
rm grouplist groupmatch
|
||||||
|
@ -11,6 +11,7 @@ clean:
|
||||||
install: \
|
install: \
|
||||||
$(BINDIR)/grouplist \
|
$(BINDIR)/grouplist \
|
||||||
$(BINDIR)/groupmatch \
|
$(BINDIR)/groupmatch \
|
||||||
|
$(BINDIR)/groupcount \
|
||||||
|
|
||||||
|
|
||||||
%: %.pl customize
|
%: %.pl customize
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!@@@perl@@@ -w
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
groupcount - count number of groups of all users
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
groupcount
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
This script counts the number of groups each user is a member of.
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Peter J. Holzer <hjp@wsr.ac.at>
|
||||||
|
|
||||||
|
=head1 SEE ALSO
|
||||||
|
|
||||||
|
id(1)
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Getopt::Long;
|
||||||
|
|
||||||
|
my $debug = 0;
|
||||||
|
my $fullname = 0;
|
||||||
|
GetOptions("debug" => \$debug,
|
||||||
|
"fullname" => \$fullname);
|
||||||
|
|
||||||
|
|
||||||
|
my $u = {};
|
||||||
|
my $g = {};
|
||||||
|
|
||||||
|
while (my @gr = getgrent()) {
|
||||||
|
|
||||||
|
my ($name,$passwd,$gid,$members) = @gr;
|
||||||
|
$g->{$gid} = $name;
|
||||||
|
for my $i (split(/ /, $members)) {
|
||||||
|
print STDERR "getgrent: $gid: $i\n" if($debug);
|
||||||
|
$u->{$i}{$name} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (my @pw = getpwent()) {
|
||||||
|
my ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw;
|
||||||
|
$u->{$name}{$g->{$gid}} = 1;
|
||||||
|
printf("%-10s %3d\n", $name, scalar(keys(%{$u->{$name}})));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue