Match until new line

I am running a server utility that allows me to view server shares and
permissions.

The command I am using is:
SHARES=Array.new
SHARES=`srvcheck \\testserver.split("\n")

This will change to be a variable.

the output is:

\testserver1\test
domain\user1 Full Control
Domain\Admin Full Control
Domain\chuser Read
Everyone Read
domain\ysergeb Read

\testserver2\BACKUPTEST
Everyone Change
BUILTIN\Administrators Read

\testserver31\DEVQA$
Everyone Full Control

\testsercver4\trymeout$
BUILTIN\Administrators Full Control

I need to match to a server and a specified share and print out all
the permissions just for that share. The .split("\n") spliuts it on
the newline, but how can I get all the information in between the new
lines.
I need \testserver2 with all it’s permissions and ignore the rest.

On Thu, Feb 08, 2007 at 12:05:06AM +0900, anon1m0us wrote:

            Everyone                Change

I need to match to a server and a specified share and print out all
the permissions just for that share. The .split("\n") spliuts it on
the newline, but how can I get all the information in between the new
lines.

.split("\n\n") will divide the output into groups split by a blank line.
Then you can match on the start of the string to find the one you want.

#sharelist = srvcheck \\\\testserver
sharelist = <<EOS
\\testserver1\test
domain\user1 Full Control
Domain\Admin Full Control
Domain\chuser Read
Everyone Read
domain\ysergeb Read

\\testserver2\BACKUPTEST
Everyone Change
BUILTIN\Administrators Read

\\testserver31\DEVQA$
Everyone Full Control

\\testsercver4\trymeout$
BUILTIN\Administrators Full Control
EOS

def find_share(sharelist, match)
re = /^#{Regexp.escape(match)}$/
sharelist.split("\n\n").find { |s| re.match(s) }
end

puts find_share(sharelist, “\\testserver2\BACKUPTEST”)

def find_share(sharelist, match)
re = /^#{Regexp.escape(match)}$/
sharelist.split("\n\n").find { |s| re.match(s) }
end

puts find_share(sharelist, “\\testserver2\BACKUPTEST”)

Or more cryptically, but much faster as it’s a single regexp scan and no
intermediate array is created:

def find_share(sharelist, match)
return $1 if /^#{Regexp.escape(match)}$\n(.*?\n)\n/m =~ sharelist +
“\n”
nil
end

puts find_share(sharelist, “\\testserver2\BACKUPTEST”)

Note that ^ and $ match start and end of line anywhere within the
string,
not just the start and end of the string.

Here find_share() also strips off the sharename, leaving just the users
and
their rights, but you can change this by moving the capture parentheses
in
the regexp if you wish.

B.

On Feb 7, 8:02 am, “anon1m0us” [email protected] wrote:

I am running a server utility that allows me to view server shares and
permissions.

The command I am using is:
SHARES=Array.new
SHARES=`srvcheck \\testserver.split(“\n”)

A small note, but that first line is totally unnecessary. You don’t
need to ‘declare’ a variable to be of a particular type before
assigning it. What you have above is similar to:

foo = 12
foo = ‘hello world’

The value in your first assignment (a new, empty array instance) is
totally discarded when you then assign the SHARES constant to a
completely different array.

WHat is sharelist = <<EOS ???