Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > format results of duplicate ldapsearch records

Reply
Thread Tools

format results of duplicate ldapsearch records

 
 
marcorice@gmail.com
Guest
Posts: n/a
 
      07-15-2005
Hello all,
I a so new to perl it's not even funny, I started 3 weeks ago.
The code below works when I do an ldapsearch for a first and last name
from a ypcat passwd list and only one ldapsearch record is returned,
but when there are many records only the last record is processed. I
believe there should be a simple solution of either a while or foreach
condition but I CANNOT find it for the life of me. Here is the code and
the ldapsearch output below, CAN ANYONE HELP ME PLEASE.

#!/bin/perl
#
my $YP="REMOVED";
my $SHOST="REMOVED";
my $PORT="REMOVED";
my $UIDs_n_IDs_NOTMATCH="./UIDs_n_IDs_Not_Match";

my @ypsearch = (`ypcat passwd | grep user`);

# Search through the list of unix userIDs from ypcat and get
information
foreach (@ypsearch) {
($unixid, $NULL, $unixuid, $group, $namefield) = split /:/;
# split the gecos field and get fullname and employeeid
($FullName, $empid)=split (/\(|\,/, $namefield);
# further split the fullname with first middle and last name
($fname,$middle,$lname)=split (/ /, $FullName);
# Compensate for people with no middle name
if (!($lname))
{
$lname = $middle;
undef ($middle);
}
print "$unixid\n";
print "unixname $fname, $middle, $lname, $empid\n";
my @hash=();
# Do ldapsearch for user and capture specific fields
$info= (`ldapsearch -p $PORT -b DC=com -s sub -h $SHOST
"(&(sn=$lname)(givenName=$fname))" givenName middleName sAMAccountName
sn employeeID mail telep
honeNumber extensionAttribute13 userPrincipalName`);
print TEMPFILE "$info\n";
close (TEMPFILE);
chomp(@test=`cat $TEMPFILE`);
$/="";

foreach (@test){
($key, $value) = split /=/, $_;
;
if ($key =~ m/extensionAttribute13/){
$ntuid = $value;
}

elsif ($key =~ m/telephoneNumber/){
$telenum = $value;
}
elsif ($key =~ m/mail=/){
$mail = $value;
}
elsif ($key =~ m/employeeID/){
if ($value eq $empid) {
$employeeid = $empid;
}
else {
$employeeid = $value;
}
}
elsif ($key =~ m/sn/){
$lastname = $value;
}
elsif ($key =~ m/sAMAccountName/){
$ntid = $value;
}
elsif ($key =~ m/middleName/){
if ("$value" eq "$middle") {
$middlename = $middle;
}
else {
$middlename = $value;
}
}
elsif ($key =~ m/givenName/){
$givenname = $value;
}
elsif ($key =~ m/userPrincipalName/){
# Remove unwanted characters, probably better of doing it but.
$value =~ s/.*@//;
$value =~ s/\..*//;
$domain = $value;
}
next if $key eq "";

# Check to see if users have and or match IDs and UIDs and send it to
appropriate files.
DO if and else statements with the variables $ntid, $middle,
$givenname.....etc

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-16-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1121444850.674340.90820
@o13g2000cwo.googlegroups.com:

> I a so new to perl it's not even funny,


Don't post the same message multiple times.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ldapsearch example in python-ldap? Nico Grubert Python 1 11-23-2006 04:11 PM
Urgent: Records duplicate on update! Paul Naude ASP .Net Datagrid Control 0 02-21-2006 09:25 AM
How to find duplicate records in ASP.net-Access ! Jameel ASP .Net 1 10-15-2005 10:12 AM
format results of duplicate ldapsearch records marcorice@gmail.com Perl Misc 0 07-15-2005 02:56 PM
Removing duplicate records from dataTable sumit ASP .Net 1 11-25-2003 10:42 AM



Advertisments