manage multiple groups
This commit is contained in:
parent
b731b3382d
commit
ebcd35d691
10
README.md
10
README.md
@ -2,18 +2,16 @@
|
|||||||
Batch import a lot of users and groups.
|
Batch import a lot of users and groups.
|
||||||
You need a CSV file with this layout:
|
You need a CSV file with this layout:
|
||||||
|
|
||||||
username Firstname Lastname group password
|
username Firstname Lastname password group1 [group2] [group3] [groupN]
|
||||||
|
|
||||||
See test.csv file for a sample.
|
See test.csv file for a sample.
|
||||||
You can use the TAB as a separator (this is the default), or whatever character you want.
|
You can use the TAB as a separator (this is the default), or whatever character you want.
|
||||||
Beware that Microsoft Excel uses the semicolon (;) as a separator instead the comma (,) for a CSV file (COMMA separated value).
|
Beware that Microsoft Excel uses the semicolon (;) as a separator instead the comma (,) for a CSV file (COMMA separated value).
|
||||||
|
|
||||||
To import, simply call the script, by passing the CSV file as a parameter and the separator as the second parameter.
|
To import, simply call the script, by passing the CSV file as a parameter and the separator as the second parameter.
|
||||||
|
|
||||||
./importa_utenti.pl test.CSV
|
./importa_utenti.pl test.CSV
|
||||||
./importa_utenti.pl test.CSV ";"
|
./importa_utenti.pl test.CSV ";"
|
||||||
./importa_utenti.pl test.CSV ","
|
./importa_utenti.pl test.CSV ","
|
||||||
|
|
||||||
The import process will create all non-existing groups. If the user already exists then the line is skipped (so if you specified a nonexistent group for this user, the group won't be created).
|
|
||||||
|
|
||||||
|
The import process will create all non-existing groups. If the user already exists then the line is skipped (so if you specify a nonexistent group for this user, the group won't be created).
|
||||||
|
@ -32,7 +32,7 @@ while(<FH>) {
|
|||||||
chomp $_;
|
chomp $_;
|
||||||
$_ =~ s/\s+$//;
|
$_ =~ s/\s+$//;
|
||||||
|
|
||||||
my ($username, $firstName, $lastName, $group, $password) = split(/$separator/, $_);
|
my ($username, $firstName, $lastName, $password, @groups) = split(/$separator/, $_);
|
||||||
|
|
||||||
if( ! $username) {
|
if( ! $username) {
|
||||||
next;
|
next;
|
||||||
@ -53,11 +53,13 @@ while(<FH>) {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$accountsDb->get($group)) {
|
foreach my $group (@groups) {
|
||||||
my $groupRecord = $accountsDb->new_record($group, {
|
if(!$accountsDb->get($group)) {
|
||||||
'type' => 'group'
|
my $groupRecord = $accountsDb->new_record($group, {
|
||||||
});
|
'type' => 'group'
|
||||||
warn "[INFO] created group $group.\n";
|
});
|
||||||
|
warn "[INFO] created group $group.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $record = $accountsDb->new_record($username, {
|
my $record = $accountsDb->new_record($username, {
|
||||||
@ -77,8 +79,10 @@ while(<FH>) {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$accountsDb->add_user_to_groups($username, $group);
|
foreach my $group (@groups) {
|
||||||
|
$accountsDb->add_user_to_groups($username, $group);
|
||||||
|
}
|
||||||
|
|
||||||
if($password) {
|
if($password) {
|
||||||
my ($pfh, $pfilename) = tempfile('import_users_XXXXX', UNLINK=>0, DIR=>'/tmp');
|
my ($pfh, $pfilename) = tempfile('import_users_XXXXX', UNLINK=>0, DIR=>'/tmp');
|
||||||
print $pfh $password;
|
print $pfh $password;
|
||||||
|
11
test.csv
11
test.csv
@ -1,6 +1,5 @@
|
|||||||
utente1 Nome1 Cognome1 utonti1 alsdlajsd
|
utente1 Nome1 Cognome1 alsdlajsd utonti1 lusers1 everybody
|
||||||
utente2 Nome2 Cognome2 utonti1 alsdlajsd
|
utente2 Nome2 Cognome2 alsdlajsd utonti1 everybody
|
||||||
utente3 Nome3 Cognome3 lusers1 alsdlajsd
|
utente3 Nome3 Cognome3 alsdlajsd lusers1 everybody
|
||||||
utente4 Nome4 Cognome4 lusers4 alsdlajsd
|
utente4 Nome4 Cognome4 alsdlajsd lusers4 lusers1 everybody
|
||||||
utente5 Nome5 Cognome5 lusers4 alsdlajsd
|
utente5 Nome5 Cognome5 alsdlajsd lusers4 everybody
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user