reran the code, was able to only get 1 account back even though I know there are hundreds more. When using this ldapsearch: ldapsearch -h server -D "cn=xxxx" -w "xxxxx" -b "ou=functionals,o=xxxx.com,o=com" -s sub '(&(|(usertype=F))(mail=*))' It's still not writing to the log either.
#!/usr/local/bin/perl -w # Modules used use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP use Mozilla::LDAP::Utils; use Mozilla::LDAP::Entry; use Mozilla::LDAP::API qw(:constant :api); use Date::Calc qw(:all); use Time::Local; use strict; use English; use locale; use FileHandle; # UM connection variables my (%ld) = Mozilla::LDAP::Utils::ldapArgs(); $ld{port} = 389; $ld{root} = "o=xxx.com,o=xxx"; $ld{base} = "ou=functionals,o=xxx.com,o=xxx"; $ld{scope} = "subtree"; my $UM_conn; my @attr = ("corpid", "usertype", "mail"); my $script_log = "Migrate_functionals"; my $functional_data_file = "functional.txt"; my $pager_data_file = "pager.txt"; my $log_directory = "/usr/users/xxx/"; my $data_directory = "/usr/users/xxxx/"; if ($ARGV[0]) { # determine environment # TODO: bind and password will be different for TEST vs. NA if ($ARGV[0] eq "TEST") { $ld{host} = "xxxxxx.com"; $ld{bind} = "cn=xxxxxxx"; $ld{pswd} = "xxxx"; } elsif ($ARGV[0] eq "PROD") { $ld{host} = "xxxxxx.com"; $ld{bind} = "cn=xxxxx"; $ld{pswd} = "xxxxxx"; } else { usage(); } } else { usage(); } print "Connecting to UM...\n"; #################################################################e # Try to connect to the UM LDAP directory ################################################################## $UM_conn = new Mozilla::LDAP::Conn(\%ld); if (!$UM_conn) { print "UM Access failed. Exiting."; exit; } #################################################################e my $record_count = 0; # How many entries we examine my $processed_record_count = 0; # How many entries we take action o +n ################################################################### # Look up user(s) in UM Directory ################################################################### # TODO: that filter is functionals not on Exchange my $entry = $UM_conn->search($ld{base}, $ld{scope}, "(&(|(usertype=F)) +(mail=*)(!(espid=4)))", 0, @attr); my $um_user_type; if (!$entry) { my $code = $UM_conn->getErrorCode(); if ($code == 0) { print "No Directory records found to process on this run.\n" } else { print "Run terminated on LDAP Error=" . $UM_conn->getErrorStri +ng() . ".\n"; } $UM_conn->close; } else { while($entry) { $record_count++; # TODO: create contact record in AD instead of migrating umaliasda +te my $functional = new FileHandle; my $pager = new FileHandle; open(FLOG, ">>$log_directory$functional_data_file") || die "can +not create Funtional file $functional_data_file\n"; if (($um_user_type =~ /F/)) { print FLOG "$entry->{usertype}[0] - Address $entry->{mail} +[0]\n"; print "Functional- $entry->{usertype}[0] - Address $entry +->{mail}[0]\n"; } else{ $entry = $UM_conn->nextEntry(); } last; } # End of while loop $UM_conn->close; print "\nRecords Examined: $record_count\n"; print "Records Updated: $processed_record_count\n\n"; print "Completed normally. $record_count records examined. $proces +sed_record_count records updated.\n"; } # End of else ($entry) 1; sub usage () { print "Usage: $0 [DEV|TEST|PROD] 2> logfile.log\n"; print " DEV - development environment\n"; print " TEST - test environment\n"; print " PROD - production environment\n"; print " logfile.log - the logfile can be used to reverse the + update\n"; print " when fed to the unmigrate_umaliasdate. +pl program.\n"; exit; }

In reply to Re^4: searching LDAP and writing to text file by mr_evans2u
in thread searching LDAP and writing to text file by mr_evans2u

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.