commit 9b1a2984783544748bd4266a93841d52d53fed81 Author: Thomas C Date: Wed Oct 16 18:49:27 2019 +0200 initial commit diff --git a/test.pl b/test.pl new file mode 100644 index 0000000..c7422f6 --- /dev/null +++ b/test.pl @@ -0,0 +1,38 @@ +#/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; + +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 $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"; +while (my $line = <$data>) { + chomp $line; + my @fields = split ";" , $line; + my $dn = $fields[0] ; + my $attr1 = $fields[1] ; + + print( $dn."\t".$attr1."\n" ) ; + my $mesg = $ldap-> modify( $dn, + changes=> [ + delete => [ 'description' ], + add => [ description => $attr1 ] + ] + ) ; + $mesg->code and warn $mesg->error; # check for errors +} \ No newline at end of file