#72442 - 2003-01-07 09:37 PM
Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
I have a string:
DOMAIN\UserName:(OI)(IO)(special access:)
And I want to extract JUST the user name. What is the easiest way to do this? I'm having a brain freeze! Thanks!!
|
|
Top
|
|
|
|
#72443 - 2003-01-07 09:46 PM
Re: Extract part of a string
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
code:
$string = "DOMAIN\UserName:(OI)(IO)(special access:)" $Account = split(split($string,":")[0],"\") $Domain = $Account[0] $Username = $Account[1] ? $Domain ? $Username
or more simply code:
? split(split($string,":")[0],"\")[1]
[ 07. January 2003, 22:00: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#72445 - 2003-01-07 09:52 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
PERFECT!! You ROCK!! Thank for the QUICK response!! I thought I needed to use SPLIT, but couldn't figure out how!
|
|
Top
|
|
|
|
#72447 - 2003-01-07 09:56 PM
Re: Extract part of a string
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
|
Top
|
|
|
|
#72450 - 2003-01-08 10:51 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
That script WAS working pefect until I ran in to a bug. Can anyone help me again??
Script works fine that was posted by Howard Bullock until my varible changed a littel bit.
Works fine when it reads this line:
F:\AGG DOMAIN\USERNAME:(OI)(CI)F
But fails when it reads this line:
F:\CMD Files DOMAIN\USERNAME:F
The error is "Script error: array reference out of bounds! $NAMEGRP = $Account[1]
I modifed Howards script a little to fit my needs and this is what I'm actually using that's giving me the error. Any help would be WELL welcomed! Thanks!!
code:
IF INSTR ("$X", "D01\") <> 0 $Account = split(split($X,":")[0],"\") $NAMEGRP = $Account[1]
|
|
Top
|
|
|
|
#72452 - 2003-01-08 11:09 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
Does it help any if I use the LEN command? I can make a variable out of the drive and directory (F:\AGG or F:\CMD Files). That way you could just count over that many characters and then extract from there.
|
|
Top
|
|
|
|
#72455 - 2003-01-08 11:16 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
I'm not changing the rules, I'm throwing out options and ideas.
code:
BREAK ON
$DIR=F:\
SHELL "CMD.EXE /E:1024 /C DIR $DIR *. /AD /B /N > $DIR\DIRS.TXT" Open(2,"$DIR\DIRS.TXT",4) WRITELINE (2,"999999999") CLOSE(2)
$INDEX2 = 0 $COUNT2 = 0
$index = 0 ; This index is used to count directories $count = 0 ; This count is used to determine how many directories have been changed
SHELL "CMD.EXE /E:1024 /C CACLS $DIR > $DIR\CACLS.TXT"
$DIRLOC = $DIR Open(1,"$DIR\CACLS.TXT",4) WRITELINE (1,"THEEND") CLOSE(1) Open(1,"$DIR\CACLS.TXT",2) Open(2,"$DIR\DIRS.TXT",2) GOTO READACL
:SUBS
; This section reads each line of DIRS.TXT file with the directory information in it.
$D = ReadLine(2) ; "$D"
; This secition will take the output file with the ACL information ; and wrote THEEND at the end of it to mark the end of the file
$DIRLOC='$DIR'+'$D' ? "$DIRLOC"
$shellstring2='cacls ' + '"$DIRLOC"'+ ' >' + ' "$DIRLOC' + '\CACLS.TXT"' ? "$SHELLSTRING2" ; SHELL "CMD.EXE /E:1024 /C CACLS $DIRLOC > $DIRLOC\CACLS.TXT" shell '%COMSPEC% /e:1024 /c '+$shellstring2
Open(1,'$DIRLOC' + \CACLS.TXT,4) WRITELINE (1,"THEEND") CLOSE(1) Open(1,$DIRLOC + \CACLS.TXT,2)
; This section reads each line of the CACLS.TXT file with the ACL information in it. ; If the line has D01\ in it, the program will extract the user name or group name ; associated with D01\ and make it the $NAMEGRP variable
:READACL
$X = ReadLine(1) ; ? "$X" IF $X = "THEEND" CLOSE(1) $COUNT2 = $COUNT2 + 1 $INDEX2 = $INDEX2 + 1 Goto SUBS Endif IF $X = "999999999" Goto Done ENDIF
IF INSTR ("$X", "EVERYONE") $Account = split(split($X,":")[0],"\") $NAMEGRP = LTRIM($Account[0]) ; ? "$NAMEGRP" GOTO PERMISSION ENDIF
IF INSTR ("$X", "D01\") <> 0 $Account = split(split($X,":")[0],"\") $NAMEGRP = $Account[1] ; ? "$NAMEGRP" GOTO PERMISSION ELSE GOTO COUNT ENDIF
:PERMISSION $P = SUBSTR($X, LEN(RTRIM($X)), 1) ; ? "$P"
IF $P='N' OR $P='R' OR $P='W' OR $P='C' OR $P='F'
; This section will take the $NAMEGRP variable and add an ACL for the same user or group ; in the BIO domain. Giving that user or group None, Read, Write, Change or Full Control.
; $shellstring='cacls ' + '$DIRLOC'+ ' /E /t /g' + ' BIO\' + '$NAMEGRP' + ':' + '$P' $shellstring='cacls ' + '$DIRLOC'+ ' /E /g' + ' BIO\' + '$NAMEGRP' + ':' + '$P' ; shell '%COMSPEC% /e:1024 /c '+$shellstring ? "$shellstring"
ENDIF
:COUNT $count = $count + 1 ;increase the count of directories $index = $index + 1 ;increment index for next pass
goto READACL ;loop and read next ACL
CLOSE (1) CLOSE (2)
:Done
? "Done!" ? ""
|
|
Top
|
|
|
|
#72456 - 2003-01-08 11:19 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
And the potential values for $X will vary greatly. $X will be a drive letter and a folder name(s). Could be F:\ could be F:\My Documents or F:\My Music Files .....etc.
|
|
Top
|
|
|
|
#72458 - 2003-01-08 11:23 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
If someone can tell me the script that would take a value like "F:\CMD Files DOMAIN\USERNAME:F" and let me count over the number of characters to cover the Drive and folder name:
code:
$S = LEN($DIRLOC + 1) ? "$S
Then extract from the \ after domain to the : before the permission. Thanks!
|
|
Top
|
|
|
|
#72459 - 2003-01-08 11:25 PM
Re: Extract part of a string
|
Anonymous
Anonymous
Unregistered
|
The script does the directory of a given folder or drive and outputs all the directory names to a TXT file. Then it goes though each folder and outputs the ACL information to another TXT file. From that TXT file it scans each ACL entry for D01\ If it finds D01\ then it will add an ACL entry for the same user name only in the BIO domain.
|
|
Top
|
|
|
|
#72461 - 2003-01-08 11:50 PM
Re: Extract part of a string
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
MikeT, you doing this the hardest way possible.
Are you trying to migrate security on member servers or domain user accounts from one domain to another?
Please detail your business needs (not your code). I think I can give you direction to complete your task in minutes. [ 08. January 2003, 23:51: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1183 anonymous users online.
|
|
|