# 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=cust006,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=cust006,dc=company" ); $entry->update($LDAP); } else{ print "Migrate Complete !!! \n";} } END # END block to close the LDAP connections in case we die somewhere { if ($LDAP) { $LDAP->unbind(); } }