I have reverted to the previous code, as I am getting no where with this exploration. This code gives me the DN from ou3 file to the OUT file, but once I hit the $entry = $dn->pop_entry(): line, it breaks again. If I do not use the pop_entry() method, each result sends the following to OUT (Net::LDAP::Search=HASH(0x1c72f1c)). Is there any other way around this problem? Thanks again.
#! perl use strict; use warnings; use diagnostics; use Net::LDAP; use Net::LDAP::Entry; use Net::LDAP::Search; use Net::LDAP::LDIF; open PERSON, "<", "ou3" or die "Cannot open 'ou3': $!"; open MGR, "<", "ou8" or die "Cannot open 'ou8': $!"; open OUT, ">", "buildAD.ldif" or die "Cannot open 'buildAD.ldif': $!"; my $HOST = "11"; my $ADMIN = "cn=d"; my $PWD = "0"; my $BASEDN = "DC=corp"; my $ldap = Net::LDAP->new("$HOST", port=>389) or die "$@"; my $dn = $ldap->bind("$ADMIN", password=>"$PWD"); my @attr = "1.1"; my $result = Net::LDAP::LDIF->new( "buildAD.ldif", "a", wrap=>40 ); my $entry = <>; while (<PERSON>){ chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr], ); next unless $dn; #make sure something is returned $entry = $dn->pop_entry(); $result->write_entry($entry); print OUT "changetype: modify"; print OUT "replace: manager"; } $dn = $ldap->unbind; #session ends close OUT or die "Cannot close in-memory file: $!"; close MGR or die "Cannot close in-memory file: $!"; close PERSON or die "Cannot close in-memory file: $!";
In reply to Re^6: Perl Builds an LDIF
by rfransix
in thread Perl Builds an LDIF
by rfransix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |