From - Tue Apr 8 18:17:58 1997 Path: news.unizar.es!news.rediris.es!news.uoregon.edu!newsxfer3.itd.umich.edu!news.maxwell.syr.edu!rill.news.pipex.net!pipex!warwick!leicester!usenet From: nmw@ion.le.ac.uk (Nigel Wade) Newsgroups: comp.sys.sgi.admin Subject: Re: how to use NIS netgroups in scripts Date: 7 Apr 1997 12:32:59 GMT Organization: University of Leicester, UK Lines: 96 Message-ID: <5iaphr$4qk@falcon.le.ac.uk> References: <3345504F.6201@execpc.com> NNTP-Posting-Host: sirius.ion.le.ac.uk X-Newsreader: knews 0.9.5 In article <3345504F.6201@execpc.com>, Jonathan Detert writes: >Hello SGI system admins, > >i made netgroups to simplify .rhost maintenance, and to simplify script >writing - e.g. i wanted to be able to say, "for all irix hosts; do", and >i thought that using a netgroup would be a decent vehicle. I'm finding >that it ain't such a decent vehicle: > > 1st: i have to strip off the parantheses, and username; > 2nd: ypmatch doesn't recursively expand nested netgroup names. > >Does anyone have a better idea for how to use NIS as the definitive >source of host names of a certain character (i.e. all irix hosts)? > >Thanks, and >-- >Happy Landings, > > Jon Detert metco@execpc.com 414.783.8527 IMHO netgroups are the best. I have appended a program which lists each entry in a netgroup. The -h/-f flags are because I have two entries for each machine, one with just the hostname, and the other with the FQDN; the flag allows me to select which I want (by default it would list both). If you build an executable called netgroup, you can have commands like, for host in `netgroup -h `; do rsh $host "commands"; done Hope this helps. -- ----------------------------------------------------------- Nigel Wade, System Administrator, Space Plasma Physics Group, University of Leicester, Leicester, LE1 7RH, UK E-mail : nmw@ion.le.ac.uk Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555 <<--- code for netgroup.c -->> #include #include #include #include void usage(void) { fprintf(stderr,"Usage: [-h] [-f] netgroup groupname\n"); exit(1); } main(int argc, char **argv) { char *machine, *user, *domain; int host_part = 0; int DNS_part = 0; int c; while( (c = getopt(argc, argv, "hf")) != -1 ) { switch(c) { case 'h' : host_part = 1; break; case 'f' : DNS_part = 1; break; } } if ( host_part == 0 && DNS_part == 0 ) { host_part = 1; DNS_part = 1; } if ( argc-optind != 1 ) usage(); setnetgrent(argv[optind]); while( getnetgrent(&machine, &user, &domain) == 1 ) { if ( strchr(machine, '.') != NULL && DNS_part == 1 ) fprintf(stdout, "%s ", machine); if ( strchr(machine, '.') == NULL && host_part == 1 ) fprintf(stdout, "%s ", machine); } endnetgrent(); fprintf(stdout, "\n"); }