Author Topic: Mass import users  (Read 5408 times)

rtupper

  • Zen Apprentice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Mass import users
« on: June 20, 2011, 05:55:24 pm »
I would like to post this to the forums because I said to Javier I would.

Hello Raymond,
  if you have managed to import users in bulk, it is very easy to add the 'comment' field. Just in the addUser call add a 'comment' field to the hash which contains the user data.

Anyway if you have more problems with this, send me the url of the forum topic and I would chime in.

Cheers,
Javier


On 20/06/11 04:05, rtupper@nb.hostopia.com wrote:
> Javier:
>
> I was wondering if there was a way to add text in the comment field when mass importing users with the bulkusers and users scripts, I have created a web page that is linked with the comments field to give users access to an external site, and there password for the site is located in the comments field. I am currently using the latest version of zentyal ebox, I am working with over 200 users and am greatful that they have made roaming profiles with the new system, we have been using our own modified ebox server for roaming profiles for some time using rsync, but I am always patching the system. Well now that we have roaming profiles integrated into the new system this makes my job ten times easier, but I wanted to start a new clean slate with this server hence why I am importing users with the bulkusers script. if you can help me with this comment field this would be great and I will try to contribute my share with the community, also is there a way to mass import groups?
> I will post this in the forums as well, I just wanted to give you a shout out first because of all the forums I have been reading with you in them, so I know you have a really good understanding of what I am trying to achieve.
>
>
> Thank You:
> Raymond


If someone would also like to tell me how to add groups as well this would be great?

rtupper

  • Zen Apprentice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #1 on: June 20, 2011, 05:57:39 pm »
I would also like to state that I do not really know how to add the comment field in this script.

#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my @users;
open (my $USERS, 'users');

while (my $line = <$USERS>) {
    chomp ($line);
    my $user;
    my ($username, $givenname, $surname, $password) = split(',', $line);
    $user->{'user'} = $username;
    $user->{'givenname'} = $givenname;
    $user->{'surname'} = $surname;
    $user->{'password'} = $password;
    push (@users, $user);
}
close ($USERS);

foreach my $user (@users) {
    $usersModule->addUser($user, 0);
}

1;

rtupper

  • Zen Apprentice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #2 on: June 20, 2011, 06:40:45 pm »
This is what I put in the script is it right

#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my @users;
open (my $USERS, 'users');

while (my $line = <$USERS>) {
    chomp ($line);
    my $user;
    my ($username, $givenname, $surname, $password) = split(',', $line);
    $user->{'user'} = $username;
    $user->{'givenname'} = $givenname;
    $user->{'surname'} = $surname;
    $user->{'password'} = $password;
    $user->{'comment'} = $comment;
    push (@users, $user);
}
close ($USERS);

foreach my $user (@users) {
    $usersModule->addUser($user, 0);
}

1;

Javier Amor Garcia

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1225
  • Karma: +12/-0
    • View Profile
Re: Mass import users
« Reply #3 on: June 21, 2011, 10:48:48 am »
Yes, this correcto. You just have to define $comment and set its value.

One way would be to add another comma-separated value with the commentary. In this case you must replace:

Code: [Select]
    my ($username, $givenname, $surname, $password) = split(',', $line);
with:
Code: [Select]
    my ($username, $givenname, $surname, $password, $comment) = split(',', $line);
And then add to the lines the comment separated with a ',' from the previous field.

Cheers,
Javier

neuropharm

  • Zen Apprentice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #4 on: August 10, 2011, 10:44:18 pm »
When adding users through the web interface, the users folder is automatically shared to the user. But when using this bulkuser script found at the top of this page http://doc.zentyal.org/en/develop.html  the user share is not created.

I am looking to import 200 users and create a share for all of the users.

Any tips, tricks, pointers? 

Thanks much!
_________________________________
Be with God, He is always with you

jsalamero

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1419
  • Karma: +45/-1
    • View Profile
Re: Mass import users
« Reply #5 on: August 13, 2011, 05:09:28 pm »
Check the _addUser method of Samba module.

biyover

  • Zen Monk
  • **
  • Posts: 62
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #6 on: March 29, 2012, 09:48:02 pm »
Hi...

I used this script before and it worked great!

But now i get:

$ sudo ./addusers.pl
Error opening 'users' file: Permission denied at ./addusers.pl line 13, <DATA> line 466.

I gather it's not the script itself, but some other part in zentyal? but why now?

half_life

  • Bug Hunter
  • Zen Hero
  • *****
  • Posts: 867
  • Karma: +59/-0
    • View Profile
Re: Mass import users
« Reply #7 on: April 01, 2012, 05:07:32 am »
The script expects to be run in the same directory as the file "users" .  You need to run this with admin privileges via sudo unless you have created a root password.

biyover

  • Zen Monk
  • **
  • Posts: 62
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #8 on: April 04, 2012, 05:29:40 am »
err, yes, I realise that. It does say "$ sudo" in my post... and the "users" file is in the same directory...

I was wondering if any updates might caused a problem, since I tried it once and it worked.

half_life

  • Bug Hunter
  • Zen Hero
  • *****
  • Posts: 867
  • Karma: +59/-0
    • View Profile
Re: Mass import users
« Reply #9 on: April 04, 2012, 09:39:54 pm »
Sorry,   the error pointed to that problem so I was responding to that.  No offense intended.

macware23

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #10 on: November 15, 2013, 03:47:49 am »
Hello. I have used the script and works perfectly. It add the users with corresponding share folder. But I found a problem when I login and logout and login again. The shared folder or mapped drive in Windows disappear. You need to restart and login again to access the shared folder or drive. Is there any FIX for this problem? By the way when you add users using the Zentyal Browser based data entry, there was no problem.

This is also the script that I use.

#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::UsersAndGroups::User;

EBox::init();

my @users;
open (my $USERS, 'users');

while (my $line = <$USERS>) {
    chomp ($line);
    my $user;
    my ($username, $givenname, $surname, $password) = split(',', $line);
    $user->{'user'} = $username;
    $user->{'givenname'} = $givenname;
    $user->{'surname'} = $surname;
    $user->{'password'} = $password;
    push (@users, $user);
}
close ($USERS);

foreach my $user (@users) {
    EBox::UsersAndGroups::User->create($user, 0);
}

1;

macware23

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #11 on: November 16, 2013, 01:53:06 pm »
I have already figure it out. The username should be in lowercase so that when you log in and logout ad login again, the shared directory or folder will not disappear. Hope this helps.

cyberfrk

  • Zen Apprentice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Mass import users
« Reply #12 on: January 12, 2015, 10:29:02 pm »
Hi,

Is it possible to mass delete users by adapting this script (in exemple with delete_users.csv)?

My research has not been successful. :(
Thks a lot