Hi Perl Monks, I am trying to use LDAP moddn to move an user entry from one branch to new branch, see below the script:
# The Script to Migrate User Segment in OUD. use lib "/xxxx/perl/perlmods/share/perl5/"; use lib "/xxxx/perl/perlmods/lib64/perl5/"; use MIME::Base64; use Net::LDAP; # PARAMETERS #ACCEPTANCE: $hostname = "xxxxxx"; $ldapport = "xxxx"; $ldapbindid = "xxxxxx"; $password = "xxxxx"; $ldapbasedn = "ou=mgusers,ou=seg90,ou=cust004,dc=company"; # Connect to the ldap(OUD) instance $LDAP = Net::LDAP->new($hostname, port => $ldapport) or die "$@"; $msg = $LDAP->bind( $ldapbindid, password => $password ); $msg->code && die " >>> LDAP CONNECTION ERROR " . $msg->code . " : " . + $msg->error(); #$msg = $LDAP->moddn( $dn, newrdn => "cn=$cn,ou=users,ou=seg10,ou=cust +006,dc=company" ); open(OUTPUT, ">", "/xxxxx/perl/perlscripts/MIG_USER_OUTPUT.csv"); my $search = $LDAP->search( base => $ldapbasedn, filter => "(uid=*)", attrs => ['cn'] ); $search->code && die " >>> LDAP SEARCH ERROR " . $search->code . " : + " . $search->error(); print OUTPUT "COUNT: ", $search->count; foreach my $entry ($search->entries) { print OUTPUT "Moving user with cn=", $entry->get_value('cn'). + "\n"; #Perform Migration of User segment in OUD my $entry = Net::LDAP::Entry->new; if ($search->entries != 0){ $cn = $entry->get_value('cn'); $dn = "cn=$cn,ou=mgusers,ou=seg90,ou=cust004,dc=company"; $entry = $LDAP->moddn ( $dn, newrdn => "cn=$cn", deleteoldrdn => "1", newsuperior => "ou=users,ou=seg10,ou=c +ust006,dc=company" ); $entry->update($LDAP); } else{ print "Migrate Complete !!! \n";} } END # END block to close the LDAP connections in case we die s +omewhere { if ($LDAP) { $LDAP->unbind(); } }
and I am end up with following error message: Can't locate object method "update" via package "Net::LDAP::ModDN" at USER_SEGMENT_MIG.pl line 50, <DATA> line 755. Could you please help on this? what is missing or what/where it is going wrong ? Thank you in advance, Best regards

In reply to ldap moddn via perl by murleehyd

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.