Fellow Monks: Straight up, I am going to give you the code and tell you what I am looking for: I am looking for a sub of a Dn the cn of a Dn to be exact here is how it comes up when I do a command line LDAPSearch on it:

fonManagerDN=cn=John A Smith JR,ou=NETWK SVCS,ou=People,o=Newco,c=US

and here is the official code I am using which works fine

use Net::LDAP; use Net::LDAP::LDIF; use Net::LDAP::Entry; # ***************************************** # # How to use this program: # # You must have the Active Perl package installed on your computer. # It may be downloaded from # http://www.activeperl.com/Products/Download/Get.plex?id=ActivePe +rl/ # # You will also need to install the perl-ldap package that supports NE +T::LDAP classes # The perl interpreter, perl.exe, must be in your path. # # ***************************************** # # ******************************************************************* # Configuration # Modify these values to customize the program # ******************************************************************* # # Set $use_credentials to 0 to bind anonymously. # When anonymous access is used, restricted data including uid can not + be accessed. $use_credentials = 0; # If $use_credentials is set to any non-zero value to use $bind_dn and + $bind_pw $bind_dn = 'anonymous'; # login ID for server $bind_pw = 'nopassword'; # password # These values are the ones to use for Newco when this program was wri +tten. $ldap_server = 'newco.corp.newco.com'; # host name of ldap server $ldap_base = 'ou=People,o=Newco,c=US'; # DN of search base # The following defines what attributes will be included in the outpu +t # enter one attribute name per line in lower case inside 'single quot +es' # and followed by a comma. @attr_list = ('cn','fonDeptName','telephoneNumber','l', 'st'); # print column header #print LDAPFILE #"InputValue:cn:fonDeptName:telephoneNumber:l:st\n"; # ************** End of configuration section *********************** # ******************************************************************* # ************** Initialization ****************** # Set up a search pattern that will recognize any attribute. $attrs = join(':', @attr_list); # Create the global variables with an assignment to null. foreach $attr (@attr_list) { ${$attr} = ""; } #print "Bind using server $ldap_server and ID of $bind_dn\n"; # establish LDAP connection $ldap = Net::LDAP->new($ldap_server); unless ($ldap){ my $errmsg = $@; print STDERR "Failed to open LDAP session. Error = $errmsg\n"; exit; } #log in if ($use_credentials) { $mesg = $ldap->bind($bind_dn, password => $bind_pw); if (scalar $mesg->code){ my $errmsg = $mesg->error; my $errcode = $mesg->code; print STDERR "Failed to bind as $bind_pw, Error = $errcode ($e +rrmsg)\n"; $ldap->unbind; exit; } } else { # print STDERR "Warning: Not using credentials. Some attributes m +ay not be available.\n"; } # ***************** main ***************** $nf="file1"; open (NEWFILE, "$nf"); $af="file2"; open (LDAPFILE, ">$af"); $sf="sysfile"; open (SYSOPS, ">$sf"); while (<NEWFILE>) { chomp; #remove newline in input string # search for any attribute matching the input string $srchresult = searchPeople($ldap,"(zcanyattribute=$_)"); # Warn if not found if ($srchresult->count == 0) { $login = $_; $gcos = $USERS{$login}; print SYSOPS "$login:$gcos:Not Found!!\n"; #print NEWFILE "$login\n"; #print "$_|Not found\n"; } # Warn if not unique elsif ($srchresult->count > 1) { print SYSOPS "$_:Yields more than 1 result:Unknown!!\n"; } # otherwise generte the output else { my $entry = $srchresult->entry(0); my $dn = $entry->dn; $outline = ""; foreach $attr (@attr_list) { # for perl-ldap .22 $$attr = $entry->get_value($attr); $outline .= "$$attr\:"; #$str=~s/ : \s* # chop ($outline); # for older versions #my @vals = $entry->get($attr); #$outline .= "$vals[0]\,"; } #print "$_: $outline\n"; #print "$_|$outline\n"; #print LDAPFILE "$_:$outline\n"; print LDAPFILE join(":",$_,$outline), "Active\n"; } } $ldap->unbind; # ********************************************** sub searchPeople # ********************************************** # Search the people branch of the tree with a designated search filter +. # { my ($ldap, $searchfilter) = @_; # Assign the search base and list of attributes that interest us my $base = $ldap_base; # call the search method and return the result my $result = $ldap->search ( base => "$base", scope => "sub", filter => "$searchfilter", attrs => \@attr_list ); } ## End of searchPeople ##

if I add fonManagerDN to the @attr_lists it pulls everything for that DN, instead of just the persons cn which is only what I want. I have tried fonManagerDN=cn and other permutations with no luck, so is it syntax or a sort of chop I need or another loop or what? Thanks

Edit: BazB added readmore tags.


In reply to LDAP DN subs by tux242

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.