Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all,=20 Im trying to get a dump of all users uids and homeMachine in our people OU in a flat file for a legacy app in the format of: uid:uid@homeMachine=20 uid2:uid2@homeMachine=20 and so on..... Ive stumbled across this module, and I'm guessing it might help me in my quest. Im not well versed in Perl. Any ideas would be greatly appreciated. Cheers, Matthew
Post Follow-up to this messageMatthew Woolnough wrote:
> Hi all,
>
> Im trying to get a dump of all users uids and homeMachine in our
> people OU in a flat file for a legacy app in the format of:
>
> uid:uid@homeMachine
> uid2:uid2@homeMachine
> and so on.....
>
> Ive stumbled across this module, and I'm guessing it might help me in
> my quest. Im not well versed in Perl.
>
> Any ideas would be greatly appreciated.
It'd be a pretty standard script, but if you say you are not well versed in
perl, you may want to look elsewhere. Here's something of what it'd look li
ke:
#!/usr/bin/perl -Tw
use strict;
use Net::LDAP qw(:all);
my $ldhost = 'ldap.some.org'; # your ldap host here
my $ldh = Net::LDAP->new($ldhost) or die "Error in connection!\n";
my $bind = $ldh->bind() or die "Error in bind!\n";
die "Error ", $bind->code, ": ", $bind->error, "\n" if $bind->code;
my $search = $ldh->search(
base=>"ou=people,dc=some,dc=org", # path to your ou=people here
scope=>'sub',
filter=>'(uid=*)', # or some other filter like '(homeMachine=*)'
attrs=>['dn', 'uid', 'homeMachine']
) or die "Error in search!\n";
if ($search->code) {
die "Err ", $search->code, " in search: ", $search->error, "\n";
}
# this assumes uid and homeMachine are single-valued attributes
for my $entry ($search->entries) {
my $uid = $entry->get_value('uid') || '';
my $machine = $entry->get_value('homeMachine') || '';
if ($uid && $machine) {
print $uid, ":", $uid, "@", $machine, "\n";
} else {
print STDERR "problem with DN: ", $entry->dn, "\n";
}
}
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.