Hi,
Im tinkering a bit with Zentyal in advance of our deployment. I managed to add users to more than one group and thought i would toss it here if someone would ever want to do that:
The script is called groupadd.pl but you can name it anything.pl I had trouble running it from /root because of permissions but it works if i put it in my /home/adminuser dir and run it with sudo.
#!/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") or die "Error opening 'users' file: $!";
while(my $line = <$USERS>) {
chomp ($line);
my $user;
my ($username,$givenname,$surname,$password,$group1, $group2) = split(',',$line);
$user->{'user'} = $username;
$user->{'givenname'} = $givenname;
$user->{'surname'} = $surname;
$user->{'password'} = $password;
print "\n Creating user: $username $givenname $surname \n";
$usersModule->addUser($user,0);
$usersModule->addUserToGroup($username, $group1);
$usersModule->addUserToGroup($username, $group2);
}
close($USERS);
1;
The script uses a csv formatted file that has to be in the same path and be called users This is its format:
Username1,Firstname1,Lastname1,Password1, Firstgroup1, Secondgroup1
Username2,Firstname2,Lastname2,Password2, Firstgroup2, Secondgroup2
etc...