1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#! /usr/bin/perl
#*********************************************************************
#
# prtnetgr -- print a host netgroup, convert the netgroup tree to a flat listing
#
# (c) 2001-2002 by Thomas Lange, lange@informatik.uni-koeln.de
# Universitaet zu Koeln
#
#*********************************************************************
# TODO: match the form (,,); currently these lines are skipped
# global variable
# %netgroup
# - - - - - - - - - - - - - - - - - - - - -
sub usage {
print <<EOM
Usage: prtnetgrp netgroup_name
prtnetgrp prints a plain list of all hosts belonging to the netgroup
EOM
}
# - - - - - - - - - - - - - - - - - - - - -
sub mklist {
my $grp = shift;
$netgroup{$grp} || return $grp;
map { mklist($_) } @{$netgroup{$grp}};
}
# - - - - - - - - - - - - - - - - - - - - -
&usage unless @ARGV;
# for debugging
#open NET, "<netgroup " or die "Can't read NIS netgroup info\n";
open NET, "ypcat -k netgroup |" or die "Can't read NIS netgroup info\n";
while (<NET>) {
next if /^\s*$/;
next if /\(/;
next if /^#/;
($grp, @members) = split;
$netgroup{$grp} = [ @members ];
}
# only one argument: the name of a host netgroup
$arg = shift;
# exit if argument is not a netgroup
exit 1 unless $netgroup{$arg};
$plist = join ' ', mklist($arg);
print "$plist\n";
exit 0;
|