We can close the "building an ldif from 2 files"; let's focus on Perl coding.

Need help with this 'working' code: 1. returns employeeID DN correctly to STDOUT if I hardcode an employeeID value in filter. however, it has dashes above it, how to remove the dashes? 2. more importantly, I want the result to be sent to OUT, all I've been able to send there is Dumper structures 3. overall, within the file <ou3 is a list of employeeIDs, I want to read in each line, search, print out the DN and the next two lines (changetype and replace) to OUT; then read in each line from a second file <ou8, another list of employeeIDs, search, and print that DN to OUT (with \n at the end); until end of both ou3 and ou8 (they have an equal number of entries). Giving us an LDIF file to import to LDAP. Here's the code, thanks for looking and helping:

#! perl -slw use strict; use warnings; use constant batchdir => "c:\temp10"; use Net::LDAP; use Data::Dumper; open PERSON, "<ou3" or die $!; open MGR, "<ou8" or die $!; open OUT, ">buildAD.ldif" or die $!; my $HOST = "a"; my $ADMIN = "b"; my $PWD = "c"; my $BASEDN = "d"; my $ldap = Net::LDAP->new( "$HOST" ) or die "$@"; my $dn = $ldap->bind( "$ADMIN", password => "$PWD", version=>3 ); my @attr = "1.1"; while (<PERSON>) { $dn = $ldap->search( #return only the person DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr], ); $dn->code && warn $dn->error; foreach $dn ($dn->entries) { push @attr, $dn->dump; } my $ev = Data::Dumper->Dump([$dn], [qw(dn)]); print OUT $ev; #never writes anything to OUT print OUT changetype: modify; #never writes anything to OUT print OUT replace: manager; #never writes anything to OUT while (<MGR>) { $mgr = $ldap->search( #return only the manager DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr], ); $mgr->code && warn $mgr->error; foreach $mgr ($mgr->entries) { push @attr, $mgr->dump; } my $evev = Data::Dumper->Dump([$mgr], [qw(mgr)]); print OUT manager: $evev; } } $dn = $ldap->unbind; #session ends close OUT; close MGR; close PERSON;

20100616 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips


In reply to Perl Builds an LDIF by rfransix

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.