[Samba] How to modify user fields with a command line ?

henri transfert hb.transfert at gmail.com
Mon Aug 29 12:54:38 UTC 2016


2016-08-05 10:19 GMT+04:00 Rowland Penny <rpenny at samba.org>:

> On Fri, 5 Aug 2016 09:46:51 +0400
> henri transfert <hb.transfert at gmail.com> wrote:
>
> > 2016-08-04 17:49 GMT+04:00 Rowland Penny <rpenny at samba.org>:
> >
> > > On Thu, 4 Aug 2016 16:44:34 +0400
> > > henri transfert <hb.transfert at gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > > On RSAT , we can see that there are some extra fields for users
> > > > account like description, office, phone number or email address.
> > > >
> > > > I already have hundreds of user accounts in Samba AD but these
> > > > extra fields have not been fed. I would like to import in
> > > > particular the email address for each existing users, however I
> > > > don't find a way to do that with a samba command line.
> > > >
> > > > Is there a way to modify these fields on existing users using a
> > > > samba command line (the next step will be to use this command in
> > > > a shell script) ?
> > > >
> > >
> > > No, samba-tool cannot do this, but it should be fairly easy to
> > > create a bash script using ldb-tools to do this.
> > >
> > > Rowland
> > >
> > >
> > Thanks for your help Rowland.
> >
> > I had a look at the LDB Tools wiki page.
> > As far as I understand, I have to generate a LDIF file containing all
> > the changes I want to add to the database, something like :
> >
> > myLDIF_file :
> > dn: CN=user1,OU=myOU,DC=mydom,DC=foo,DC=fr
> > changetype: modify
> > add: mail
> > mail: user1 at foo.fr
> >
> > dn: CN=user2,OU=myOU,DC=mydom,DC=foo,DC=fr
> > changetype: modify
> > add: mail
> > mail: user2 at foo.fr
> > etc ...
> >
> > and use $ ldbmodify -H samba_home/private/sam.ldb myLDIF_file to
> > modify the Samba AD database.
> > Am I on the right way ?
> >
> > If yes , where can I find the exact syntax of this special form of
> > LDIF format ?
> >
> > Thanks in advance
> >
> > Henri
>
> Well you could it that way, your ldif format looks correct, but I would
> use variables for the username and email address i.e
>
> USERLDIF="dn: CN=$USER,OU=myOU,DC=mydom,DC=foo,DC=fr
> changetype: modify
> add: mail
> mail: $EMAIL"
>
> echo "$USERLDIF" | ldbmodify -H samba_home/private/sam.ldb
>
> Wrap this in some form of loop and drag the required info in from an
> array or csv
>
> Rowland
>

Thanks for your help Rowland.
With your suggestion, I have been able to transfer information of about 300
users from a corporate LDAP serveur to Samba in about 2min.
And I am sure I will reuse some of my scripts and this method in the
future.
Great !


More information about the samba mailing list