From: Troy on 6 May 2010 13:49 Actually, what you have there looks like the returns you get from the LDAP tcl package. Is that right? If so, what you have there is a list and you are trying to do some string parsing on it. What is way easier is to iterate over the results to find the attribute you are looking for. set results [::ldap::search $handle ....your search here....] foreach result $results { foreach {object attributes} $result { foreach {name value} $attributes { if {$name = "Name"} { set rh_file(abce) $value } } } } Using list processing on lists takes care of the pathological edge cases better than trying to construct regexps.
From: rfransix on 6 May 2010 14:15 On May 6, 12:20 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On May 6, 6:48 pm, rfransix <rfran...(a)comcast.net> wrote: > > > > > > > On May 6, 11:28 am, rfransix <rfran...(a)comcast.net> wrote: > > > > On May 6, 11:19 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > On May 6, 10:49 am, "Larry W. Virden" <lvir...(a)gmail.com> wrote: > > > > > > On May 6, 11:04 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > > > So it fills in the spaces with pound signs, what's up with that?- Hide quoted text - > > > > > > > - Show quoted text - > > > > > > What version of Tcl are you using, and on what platform? > > > > > > Here's what I see with Tcl 8.5.4: > > > > > > $ cat tst.tcl > > > > > #! /usr/tcl85/bin/tclsh8.5 > > > > > > set rh_file(abce) "" > > > > > > set tmp > > > > > {uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > > > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} > > > > > > puts "lindex $tmp 1 is [lindex $tmp 1]" > > > > > > set rc [regexp {^Name=(.*)} [lindex $tmp 1] -> rh_file(abce)] > > > > > > puts "Encountered $rh_file(abce), rc = $rc" > > > > > $ ./tst.tcl > > > > > lindex > > > > > uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > > > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp} 1 is > > > > > Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp > > > > > Encountered CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp, rc = 1 > > > > > > Notice that I got into $tmp differently than your previous code - > > > > > perhaps your real life data requires the double lindex, but the same > > > > > you provided didn't require going that deep. > > > > > > Note that I tried my script against Tcl 8.6 and it worked the same > > > > > there as well. > > > > > > I recommend using a small coherent example script to work out the > > > > > details of what you are trying to do. This allows you to tweak the > > > > > data to make it follow your live data closely without violating > > > > > privacy concerns. Once you have the exact data, and a small amount of > > > > > Tcl code that demonstrates the issue, including the same script allows > > > > > others on the same platform, or alternative platforms, to see if the > > > > > problem is common or unique to your site. > > > > > Unfortunately, this Windows Server 2003 is running tcl8.3- Hide quoted text - > > > > > - Show quoted text - > > > > When I run the tcl script with set rh_file(abce) "", it returns an > > > error, or with $rh_file(abdc) "" > > > > wrong # args: should be "set varName ?newValue?" > > > while compiling > > > "set $rh_file(manager) to """- Hide quoted text - > > > > - Show quoted text - > > > my mistake, should be just: set rh_file(abce) "" > > and that works as expected, thank you. > > > the single lindex fails in my script. > > > The double lindex works great, except for changing the spaces to > > pounds. here's what I'm working on, which is not working: > > > if { [regexp {^Name=(.*)} [lindex [lindex $tmp 0] 1] -> rh_file(abce)] > > == 0 } then { > > regsub -all "#" $rh_file(abce) " " -> rh_file(abce)} else { > > > set rh_file(abce) "" > > > } > > You got it reversed; [regexp] returns 0 when there has been no match. > > -Alex- Hide quoted text - > > - Show quoted text - While the tcl script (v8.3 on windows server) runs to completion with this code, between the point $tmp is created and after regexp is run, these pound signs are getting substituted for spaces. This if statement is not (re)substituted spaces for pound signs, any ideas? if { [regexp {^Name=(.*)} [lindex [lindex $tmp 0] 1] -> rh_file(abce)] == 1 } then { regsub -all "#" $rh_file(abce) " " -> rh_file(abce) } else { set rh_file(abce) "" } $tmp: uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} $rh_file(manager): CN=Buggs\\, Bunny D.,OU=Users,OU=Corporate,DC=corp
From: rfransix on 6 May 2010 14:26 On May 6, 1:15 pm, rfransix <rfran...(a)comcast.net> wrote: > On May 6, 12:20 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> > wrote: > > > > > > > On May 6, 6:48 pm, rfransix <rfran...(a)comcast.net> wrote: > > > > On May 6, 11:28 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > On May 6, 11:19 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > > On May 6, 10:49 am, "Larry W. Virden" <lvir...(a)gmail.com> wrote: > > > > > > > On May 6, 11:04 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > > > > So it fills in the spaces with pound signs, what's up with that?- Hide quoted text - > > > > > > > > - Show quoted text - > > > > > > > What version of Tcl are you using, and on what platform? > > > > > > > Here's what I see with Tcl 8.5.4: > > > > > > > $ cat tst.tcl > > > > > > #! /usr/tcl85/bin/tclsh8.5 > > > > > > > set rh_file(abce) "" > > > > > > > set tmp > > > > > > {uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > > > > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} > > > > > > > puts "lindex $tmp 1 is [lindex $tmp 1]" > > > > > > > set rc [regexp {^Name=(.*)} [lindex $tmp 1] -> rh_file(abce)] > > > > > > > puts "Encountered $rh_file(abce), rc = $rc" > > > > > > $ ./tst.tcl > > > > > > lindex > > > > > > uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > > > > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp} 1 is > > > > > > Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp > > > > > > Encountered CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp, rc = 1 > > > > > > > Notice that I got into $tmp differently than your previous code - > > > > > > perhaps your real life data requires the double lindex, but the same > > > > > > you provided didn't require going that deep. > > > > > > > Note that I tried my script against Tcl 8.6 and it worked the same > > > > > > there as well. > > > > > > > I recommend using a small coherent example script to work out the > > > > > > details of what you are trying to do. This allows you to tweak the > > > > > > data to make it follow your live data closely without violating > > > > > > privacy concerns. Once you have the exact data, and a small amount of > > > > > > Tcl code that demonstrates the issue, including the same script allows > > > > > > others on the same platform, or alternative platforms, to see if the > > > > > > problem is common or unique to your site. > > > > > > Unfortunately, this Windows Server 2003 is running tcl8.3- Hide quoted text - > > > > > > - Show quoted text - > > > > > When I run the tcl script with set rh_file(abce) "", it returns an > > > > error, or with $rh_file(abdc) "" > > > > > wrong # args: should be "set varName ?newValue?" > > > > while compiling > > > > "set $rh_file(manager) to """- Hide quoted text - > > > > > - Show quoted text - > > > > my mistake, should be just: set rh_file(abce) "" > > > and that works as expected, thank you. > > > > the single lindex fails in my script. > > > > The double lindex works great, except for changing the spaces to > > > pounds. here's what I'm working on, which is not working: > > > > if { [regexp {^Name=(.*)} [lindex [lindex $tmp 0] 1] -> rh_file(abce)] > > > == 0 } then { > > > regsub -all "#" $rh_file(abce) " " -> rh_file(abce)} else { > > > > set rh_file(abce) "" > > > > } > > > You got it reversed; [regexp] returns 0 when there has been no match. > > > -Alex- Hide quoted text - > > > - Show quoted text - > > While the tcl script (v8.3 on windows server) runs to completion with > this code, between the point $tmp is created and after regexp is run, > these pound signs are getting substituted for spaces. This if > statement is not (re)substituted spaces for pound signs, any ideas? > > if { [regexp {^Name=(.*)} [lindex [lindex $tmp 0] 1] -> rh_file(abce)] > == 1 } then { > regsub -all "#" $rh_file(abce) " " -> rh_file(abce)} else { > > set rh_file(abce) "" > > } > > $tmp: > uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} > > $rh_file(manager): > CN=Buggs\\, Bunny D.,OU=Users,OU=Corporate,DC=corp- Hide quoted text - > > - Show quoted text - I haven't tried ldap::search commands, I don't believe they are supported in our version. But I'll test drive your suggestion. I have the results from this command: set rc [regexp ..........rh_file(abce)] puts "Encountered $rh_file(abce), rc = $rc" And, it placed the correctly parsed value, without the pound signs, in the trace output file: Encountered Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp, rc = 1 So, that means, it is NOT regexp doing the # to space substitution. Stay tuned, looking for the answer.
From: rfransix on 6 May 2010 14:37 On May 6, 1:26 pm, rfransix <rfran...(a)comcast.net> wrote: > On May 6, 1:15 pm, rfransix <rfran...(a)comcast.net> wrote: > > > > > > > On May 6, 12:20 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> > > wrote: > > > > On May 6, 6:48 pm, rfransix <rfran...(a)comcast.net> wrote: > > > > > On May 6, 11:28 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > > On May 6, 11:19 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > > > On May 6, 10:49 am, "Larry W. Virden" <lvir...(a)gmail.com> wrote: > > > > > > > > On May 6, 11:04 am, rfransix <rfran...(a)comcast.net> wrote: > > > > > > > > > So it fills in the spaces with pound signs, what's up with that?- Hide quoted text - > > > > > > > > > - Show quoted text - > > > > > > > > What version of Tcl are you using, and on what platform? > > > > > > > > Here's what I see with Tcl 8.5.4: > > > > > > > > $ cat tst.tcl > > > > > > > #! /usr/tcl85/bin/tclsh8.5 > > > > > > > > set rh_file(abce) "" > > > > > > > > set tmp > > > > > > > {uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > > > > > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} > > > > > > > > puts "lindex $tmp 1 is [lindex $tmp 1]" > > > > > > > > set rc [regexp {^Name=(.*)} [lindex $tmp 1] -> rh_file(abce)] > > > > > > > > puts "Encountered $rh_file(abce), rc = $rc" > > > > > > > $ ./tst.tcl > > > > > > > lindex > > > > > > > uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > > > > > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp} 1 is > > > > > > > Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp > > > > > > > Encountered CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp, rc = 1 > > > > > > > > Notice that I got into $tmp differently than your previous code - > > > > > > > perhaps your real life data requires the double lindex, but the same > > > > > > > you provided didn't require going that deep. > > > > > > > > Note that I tried my script against Tcl 8.6 and it worked the same > > > > > > > there as well. > > > > > > > > I recommend using a small coherent example script to work out the > > > > > > > details of what you are trying to do. This allows you to tweak the > > > > > > > data to make it follow your live data closely without violating > > > > > > > privacy concerns. Once you have the exact data, and a small amount of > > > > > > > Tcl code that demonstrates the issue, including the same script allows > > > > > > > others on the same platform, or alternative platforms, to see if the > > > > > > > problem is common or unique to your site. > > > > > > > Unfortunately, this Windows Server 2003 is running tcl8.3- Hide quoted text - > > > > > > > - Show quoted text - > > > > > > When I run the tcl script with set rh_file(abce) "", it returns an > > > > > error, or with $rh_file(abdc) "" > > > > > > wrong # args: should be "set varName ?newValue?" > > > > > while compiling > > > > > "set $rh_file(manager) to """- Hide quoted text - > > > > > > - Show quoted text - > > > > > my mistake, should be just: set rh_file(abce) "" > > > > and that works as expected, thank you. > > > > > the single lindex fails in my script. > > > > > The double lindex works great, except for changing the spaces to > > > > pounds. here's what I'm working on, which is not working: > > > > > if { [regexp {^Name=(.*)} [lindex [lindex $tmp 0] 1] -> rh_file(abce)] > > > > == 0 } then { > > > > regsub -all "#" $rh_file(abce) " " -> rh_file(abce)} else { > > > > > set rh_file(abce) "" > > > > > } > > > > You got it reversed; [regexp] returns 0 when there has been no match. > > > > -Alex- Hide quoted text - > > > > - Show quoted text - > > > While the tcl script (v8.3 on windows server) runs to completion with > > this code, between the point $tmp is created and after regexp is run, > > these pound signs are getting substituted for spaces. This if > > statement is not (re)substituted spaces for pound signs, any ideas? > > > if { [regexp {^Name=(.*)} [lindex [lindex $tmp 0] 1] -> rh_file(abce)] > > == 1 } then { > > regsub -all "#" $rh_file(abce) " " -> rh_file(abce)} else { > > > set rh_file(abce) "" > > > } > > > $tmp: > > uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef > > {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} > > > $rh_file(manager): > > CN=Buggs\\, Bunny D.,OU=Users,OU=Corporate,DC=corp- Hide quoted text - > > > - Show quoted text - > > I haven't tried ldap::search commands, I don't believe they are > supported in our version. But I'll test drive your suggestion. > > I have the results from this command: > set rc [regexp ..........rh_file(abce)] > puts "Encountered $rh_file(abce), rc = $rc" > > And, it placed the correctly parsed value, without the pound signs, in > the trace output file: > > Encountered Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp, rc > = 1 > > So, that means, it is NOT regexp doing the # to space substitution. > > Stay tuned, looking for the answer.- Hide quoted text - > > - Show quoted text - Does this make sense to anyone? The next step we take is to build a changetype data input file for an ldapmodify to an AD server: like this, here is where the pound signs are substituted, will AD accept this file as valid? changetype:modify department:00111 - description:Status: Active ADsPath:LDAP://myadserver/DC=corp/OU=Corporate/OU=Users/CN=Buggs\, Bunny D. userAccountControl:111 givenName:Buggs postalCode:92510 sn:Bunny streetAddress:Warner Brothers Avenue telephoneNumber:555-555-5555 title:Cartoon Character msExchHideFromAddressLists:0 manager:CN=Warner\,#Brothers#A.,OU=Users,OU=Corporate,DC=corp
From: Bruce on 6 May 2010 14:49
rfransix wrote: > On May 6, 11:19 am, rfransix <rfran...(a)comcast.net> wrote: >> On May 6, 10:49 am, "Larry W. Virden" <lvir...(a)gmail.com> wrote: >> >> >> >> >> >>> On May 6, 11:04 am, rfransix <rfran...(a)comcast.net> wrote: >>>> So it fills in the spaces with pound signs, what's up with that?- Hide quoted text - >>>> - Show quoted text - >>> What version of Tcl are you using, and on what platform? >>> Here's what I see with Tcl 8.5.4: >>> $ cat tst.tcl >>> #! /usr/tcl85/bin/tclsh8.5 >>> set rh_file(abce) "" >>> set tmp >>> {uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef >>> {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp}} >>> puts "lindex $tmp 1 is [lindex $tmp 1]" >>> set rc [regexp {^Name=(.*)} [lindex $tmp 1] -> rh_file(abce)] >>> puts "Encountered $rh_file(abce), rc = $rc" >>> $ ./tst.tcl >>> lindex >>> uid=001110001,ou=People,ou=abc,ou=abcd,o=abcde,cn=Users,cn=abcdef >>> {Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp} 1 is >>> Name=CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp >>> Encountered CN=Buggs\\, Bunny D,OU=Users,OU=Corporate,DC=corp, rc = 1 >>> Notice that I got into $tmp differently than your previous code - >>> perhaps your real life data requires the double lindex, but the same >>> you provided didn't require going that deep. >>> Note that I tried my script against Tcl 8.6 and it worked the same >>> there as well. >>> I recommend using a small coherent example script to work out the >>> details of what you are trying to do. This allows you to tweak the >>> data to make it follow your live data closely without violating >>> privacy concerns. Once you have the exact data, and a small amount of >>> Tcl code that demonstrates the issue, including the same script allows >>> others on the same platform, or alternative platforms, to see if the >>> problem is common or unique to your site. >> Unfortunately, this Windows Server 2003 is running tcl8.3- Hide quoted text - >> >> - Show quoted text - > > When I run the tcl script with set rh_file(abce) "", it returns an > error, or with $rh_file(abdc) "" > > wrong # args: should be "set varName ?newValue?" > while compiling > "set $rh_file(manager) to """ > remove the $ |