50 lines
1.4 KiB
Perl
50 lines
1.4 KiB
Perl
#/usr/bin/perl
|
|
|
|
# on abandonne python pour perl
|
|
# ce script est capable de rajouter l'attribut description avec une valeur issue
|
|
# d'un fichier csv passé en argument
|
|
use strict;
|
|
use Net::LDAP;
|
|
use Text::CSV;
|
|
|
|
my $ldapserver = "localhost";
|
|
my $binddn = "cn=manager,o=od";
|
|
my $bindpw = "123Soleil" ;
|
|
|
|
my $ldap = Net::LDAP->new( $ldapserver ) or die "$@" ;
|
|
|
|
my $mesg = $ldap->bind( $binddn,
|
|
password => $bindpw
|
|
);
|
|
|
|
$mesg->code and die $mesg->error; # check for errors
|
|
my $csv = Text::CSV->new({ sep_char => ';' }) ;
|
|
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n" ;
|
|
|
|
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
|
|
my @cols = @{$csv->getline ($data)};
|
|
foreach my $c (@cols){
|
|
print "columne: ". $c ."\t" ;
|
|
}
|
|
my $row = {} ;
|
|
$csv->bind_columns (\@{$row}{@cols});
|
|
while ($csv->getline ($data)) {
|
|
my $dn = $row->{dn} ;
|
|
my $attr1 = $row->{seeAlso} ;
|
|
my $attr2 = $row->{l} ;
|
|
|
|
# my $mesg = $ldap-> search(
|
|
# base=> $dn,
|
|
# scope=> "base",
|
|
# filter=> "(description=".$attr1.")") ;
|
|
# print $mesg->count() ;
|
|
# if ($mesg->count() != 0) { next ; }
|
|
print( $dn."\t".$attr1."\n" ) ;
|
|
my $mesg = $ldap-> modify( $dn,
|
|
changes=> [
|
|
replace => [ 'description'=> $attr1 ],
|
|
replace => [ 'l' => $attr2 ],
|
|
]
|
|
) ;
|
|
$mesg->code and warn $mesg->error; # check for errors
|
|
} |