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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |