Logo
  • Home
  • About
  • Services
  • Blogs
  • Career
  • Contact
Logo

The UK's #1 Software Development Company. PodTech IO builds custom software solutions for businesses. Call today for a free consultation

  • Address

    4th Floor, 4 Tabernacle Street London EC2A 4LU
  • Email

    info@podtech.com
  • Contact

    +44 (0) 20 8720 6583

Recursively Expand a NIS Netgroup

  • Home
  • Recursively Expand a NIS Netgroup
  • By podtech
  • In Perl

Recursively Expand a NIS Netgroup


 @results=expand_ng();


# Given a netgroup, will return a list of members.  Will recurse
# netgroups if the $recurse flag is set
sub expand_ng
{
        my($netgroup)=@_;
        my(@returnng);
        my($ng)=`ypmatch $netgroup netgroup`;
        $? != 0 and return;     #Don't continue for duff netgroups
        my($value);
        $ng =~ s/\s+/ /g;       #Compress whitespace
        $ng =~ s/\s+,/,/g;      #Remove space before a comma
        $ng =~ s/,\s+/,/g;      #Remove space after a comma

        foreach $value (split /\s+/,$ng)
        {
                # A member will either be a  tuple in brackets or another
                # netgroup.
                if($value =~ /^[^(]/)
                {
                        if ($recurse)
                        {
                                $debug and print "::recursing $value\n";
                                push (@returnng,expand_ng($value));
                        }
                        else
                        {
                                $debug and print "::adding(non-recursed) $value\n";
                                push (@returnng,$value);
                        }
                }
                else
                {
                        $debug and print "::adding $value\n";
                        push (@returnng,$value);
                }
        }
        return @returnng;
}
NIS NetgroupPerlRecursively ExpandRecursively Expand a NIS Netgroup
RedHat vs Ubuntu – Useful Package Commands
Perl – Trim Text, Trim String

Recent Posts

  • DevOps as a Software Development Methodology
  • How Does Spiral Software Development Methodology Work?
  • Waterfall Software Development Methodology And When To Use It
  • What Exactly Is Lean Software Development Methodology?
  • What is Kanban and How Does It Work?

PodTech IO

The UK's #1 Software Development Company. PodTech IO builds custom software solutions for businesses. Call today for a free consultation

Company

  • About
  • Services
  • Contact
  • Blogs
  • Career

Terms

  • Terms & Conditions
  • Privacy Policy

Contact Us

  • ADDRESS

    Headquarter: Tabernacle Street London India: Vi john Tower, Gurgaon, Haryana
  • EMAIL

    info@podtech.com
  • CONTACT

    +44 (0) 20 8720 6583

Copyright ©2023 PodTech IO. All Rights Reserved

Logo