#-----Extract Moved Users-----# sub ExtractUsers { my $foundUser = "n"; my $foundDN = "n"; my $matchUser = -1; my $foundOrg = -1; my $lenLine = 0; my $readLine = 0; my $foundFirst = "n"; my $totalFound = 0; my $statusLine = 0; my $myArray = 0; print "ExtractUsers\n"; open(FILE, "< $backupPathDir") or die "Can't Find or Open $backupPathDir: $!"; # File output - writing to print "backupPathDir: $backupPathDir\n";; open(NEW, "> $ldap_move_file") or die "can't open $ldap_move_file: $!"; print "ldap_move_file: $ldap_move_file\n"; while () { # Good practice to store $_ value because # subsequent operations may change it. my($line) = $_; # Good practice to always strip the trailing # newline from the line. chomp($line); #print "line = $line\n"; ++$readLine; ++$statusLine; if ($statusLine eq 20000) { print "Processing Lines: $readLine\n"; $statusLine = 0; } $lenLine = length($line); #print "lenline = $lenLine\n"; # Skip if found blank line and also statement with line id "entry-id" if (($lenLine > 1) && (index($line,'entry-id') eq -1)){ # checking whether the line contains o=mail,dc=company,dc=com $foundOrg = index($line, $org_suffix); if ($foundOrg > 0) { $foundUser = "n"; $foundDN = "y"; if ($totalFound eq scalar(@userArray)) { exit (0); } } #print "FoundOrg = $foundOrg\n"; #print "foundDN = $foundDN\n"; if ($foundDN eq "y") { $line =~ s/People/$move_suffix/g; #print "***Line = $line\n"; #$userArray = @userArray; foreach $myArray (@userArray) { #$userArray =$_; #print "userArray = $userArray\n"; $matchUser = index($line, $myArray); #print "matchuser = $matchUser\n"; if ($matchUser > 0) { if ($foundFirst eq "y") { # Insert a blank line after each users but not for first found user (print NEW "\n") or die "can't write to $ldap_move_file: $!"; } (print NEW $line . "\n") or die "can't write to $ldap_move_file: $!"; $foundFirst = "y"; $foundUser = "y"; ++$totalFound; } else { $foundDN = "n"; } } } else { if ($foundUser eq "y") { if (index($line, "nsUniqueId") eq -1) { (print NEW $line . "\n") or die "can't write to $ldap_move_file: $!"; } } } } } close(FILE) or die "can't close $backupPathDir: $!"; close(NEW) or die "can't close $ldap_move_file: $!"; my $test = `rm $backupPathDir`; my $logfile = $step1_logfile . `date '+%m%d%Y'`; chomp ($logfile); $logfile = "$logfile" . "." . $step1_log_ext; print "OutputLog: $logfile\n"; open(READ, "< $ldap_move_file") or die "Can't Find or Open $ldap_move_file: $!"; # Appending TO the Log files open(WRITE, ">> $logfile") or die "Can't Find or Open $logfile: $!"; print WRITE "**Step #5 Creating a Move User LDIF File\n"; print WRITE "========================================\n"; while () { # Good practice to store $_ value because # subsequent operations may change it. my($line) = $_; # Good practice to always strip the trailing # newline from the line. chomp($line); print WRITE "$line\n"; } print WRITE "\n"; close(READ) or die "can't close $ldap_move_file: $!"; close(WRITE) or die "can't close $logfile: $!"; }