Re: Script to modify NIS maps



On Sep 20, 11:08 am, littlehelph...@xxxxxxxxx wrote:
On Sep 19, 3:32 pm, William James <w_a_x_...@xxxxxxxxx> wrote:

On Sep 19, 2:18 pm, littlehelph...@xxxxxxxxx wrote:

On Sep 19, 1:47 pm, William James <w_a_x_...@xxxxxxxxx> wrote:

On Sep 19, 10:55 am, littlehelph...@xxxxxxxxx wrote:

On Sep 19, 11:17 am, William James <w_a_x_...@xxxxxxxxx> wrote:

On Sep 19, 9:38 am, littlehelph...@xxxxxxxxx wrote:

On Sep 18, 9:50 am, littlehelph...@xxxxxxxxx wrote:

Does anyone know of a script or method to remove users from NIS maps
via a script. I have been trying to accomplish this via sed, Perl ,
etc but cannot get it to work. The main issue is each NIS maps has a
different format. Does anyone know of one Perl command, or any other
means, that would accomplish this? Thanks.

Anyone know of anything that can help me accomplish this?

Give us a small sample of an NIS map.

William,
There are numerous maps I would be looking to edit via the tool/
script. Such maps as netgroup, group,

i.e - I want to remove foo3 from all maps below. You see the format
and placement will vary on different maps.

group: foousers:*:9999:foo1,foo2,foo4,foo3
netgroup: (,foo1,) (,foo2,) (,foo3,) (,foo4,)
printers: foo3 hp11

# Produces array of nonmatching and matching
# substrings. The size of the array will
# always be an odd number. The first and the
# last item will always be nonmatching.
function shatter( s, shards, regexp )
{ gsub( regexp, "\1&\1", s )
return split( s, shards, "\1" )

}

BEGIN { target = "foo3" }

{
size = shatter( $0, array, "[:,()]+" )
if (1 == size)
shatter( $0, array, "[ \t]+" )
out = ""
p = 0
for (i=1; i in array; i++)
if ( array[i] == target )
{ p = i
break
}
if (0 == p)
out = $0
else
for (i=1; i in array; i++)
{
if (i == p-1 )
{ if ( "(," == array[i] )
continue
}
else if ((i == p) || (i == p+1) )
continue
out = out array[i]
}
print out

}

==== input ====
foousers:*:9999:foo1,foo2,foo4,foo3
(,foo1,) (,foo2,) (,foo3,) (,foo4,)
(,foo3,)
foo3 hp11
bar foo3 hp11
foo3
==== output ====
foousers:*:9999:foo1,foo2,foo4,
(,foo1,) (,foo2,) (,foo4,)

hp11
bar hp11

William,
Thanks for the info. This seems like a good start to what I need.
However, I have two questions for you
1) For the section "BEGIN { target = "foo3" }" how do I see this up
to take info from a for loop or from a file? Do I use an OPEN
statement?
2) The above output does the job on the netgroups and the groups.
However, I would like to have the entire entry for foobar3 removed
from the other maps. In these maps the foobar entry is on a line by
itself. Is this a situation for a case style statement? One for
netgroups, one for groups, one for printers, etc or can this be
accomplished in another manner?
Thanks again for your help.

This version removes blank lines.
The target is passed on the command-line:
awk -f remove.awk target=foo3 datafile

#!awk
# Provide target on command-line before filename.
# E.g., target="foo3"

# Produces array of nonmatching and matching
# substrings. The size of the array will
# always be an odd number. The first and the
# last item will always be nonmatching.
function shatter( s, shards, regexp )
{ gsub( regexp, "\1&\1", s )
return split( s, shards, "\1" )

}

{
size = shatter( $0, array, "[:,()]+" )
if (1 == size)
shatter( $0, array, "[ \t]+" )
out = ""
p = 0
for (i=1; i in array; i++)
if ( array[i] == target )
{ p = i
break
}
if (0 == p)
out = $0
else
for (i=1; i in array; i++)
{
if (i == p-1 )
{ if ( "(," == array[i] )
continue
}
else if ((i == p) || (i == p+1) )
continue
out = out array[i]
}
if ( out !~ /^[ \t]*$/ )
print out

}

William,
I ran the script as decribed above but I keep getting an error at
the initial function - not sure why
Steps taken - copied the script as remove.aw and made it executable.
I then ran
awk -f remove.awk target=foo3 datafile
and received he following message
awk: syntax error near line 9
awk: bailing out near line 9


If you have nawk, use it instead of awk because on some
systems awk is very old and lacks many useful features.
Under Solaris, use /usr/xpg4/bin/awk.

.



Relevant Pages

  • Re: Script to modify NIS maps
    ... via a script. ... I have been trying to accomplish this via sed, Perl, ... There are numerous maps I would be looking to edit via the tool/ ... awk -f remove.awk target=foo3 datafile ...
    (comp.unix.shell)
  • Re: Script to modify NIS maps
    ... via a script. ... I have been trying to accomplish this via sed, Perl, ... There are numerous maps I would be looking to edit via the tool/ ...
    (comp.unix.shell)
  • Re: Script to modify NIS maps
    ... via a script. ... I have been trying to accomplish this via sed, Perl, ... There are numerous maps I would be looking to edit via the tool/ ...
    (comp.unix.shell)
  • Re: How to rewrite with awk?
    ... > I'm unfamiliar with tools such as sed & awk. ... Extract the string that matches a RE. ... This script will not only expand all the lines that say "include ... file) and not resetting ARGV(the tmp file), it then lets awk do any ...
    (comp.unix.shell)
  • Re: for loop (?)
    ... you should use awk variables in awk scripts instead ... >>of shell variables to avoid problems when those shell variables include ... I doubt if I've ever written a shell script that's robust ... > extra effort to make the script robust against weird inputs. ...
    (comp.unix.shell)

Loading