For Programmers: Free Programming Magazines  


Home > Archive > LDAP > May 2005 > output formatting









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author output formatting
Matthew Woolnough

2005-05-20, 4:06 am

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
Elliot Foster

2005-05-23, 8:59 pm

Matthew 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 like:

#!/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";
}
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com