I am pretty new to Nextcloud and also to Linux.
I looking to find a way to import users without using the web-interface or adding them manually via occ.
I managed to write a script that reads a csv-file and adds the users in there to groups, adds the email and adds a quota.
The problem is sometimes users are in more, sometimes in less groups.
I managed to add different groups by four variables for four groups. But this only works when each field for the groups is set. When I leave a field empty the script does not work because I guess occ does not accept empty values.
So need somekind of placeholder in the csv-file in the field for the groups that i do not need and so that they are not used in script.
My csv-file is something like this:
surname, name;name;group1;group2;group3;group4;email;quota
What I need is a solution to use a csv-file like above without the need to fill every group-field.
Something like that:
surname, name;name;group1;group2;;group4;email;quota
To use group3 as an example I tried NULL, \N, ‘’ and many other things. But this only creates groups with the values typed in. To be exactly NULL for example creates a group “NULL”. Of course this is not what I want.
Anyone an idea? I would appreciate every kind of help.
Many thx for your answer.
In the meanwhile I found a solution to my problem. I now use a check if there is an empty string in .csv-file.
Dependig if yes or no the script does different commands.
Like that:
This works great and my script can now add users with a random pw int different groups with a range of one to four groups and also adding email and quota in once.
Thank you for share the script and share how make the csv.
I just have one question why you have 4 groups ? Is something important ?
May be is from database ? I see in database different tables for groups and id of groups.
Why ask, I have 2 groups admins, clients, may be make one more group.
I make the script and csv with you suggest but is only give me password on terminal not added users.
And when the script add users ?
In db have
table oc_users
table oc_accounts
linuxman you’re not using the right separator in your csv: it must be ; and not ,
Groups are not mandatory: you can add 4 groups per user, or leave it blank
Hello,
Now I successful add users to Nexcloud with script and is maked Display name, username, password but not set the quota for disk usage
Below is script I change it some parts :
But to make the script work I change the part of code in Manager.php in
/home/user/public_html/lib/private/User/Manager.php line around 317 if (preg_match('/[^a-zA-Z0-9 _\.@\-\']/', $uid)) {
to if (preg_match('/[^a-zA-Z0-9 _\.@\-\']/', $var_username)) {
But my problem is if possible not make csv but only txt (I think is possible.
And if I add more users to file script check if user exist make all below users and not stop when users exist.
Hello,
I some new edit of script and now all import from file is ok.
User add username, user group (I have 1 group for users), email and password, and read the settings of quota and add it two.
csv file I edit it from (geany text editor not excel) and need to have below columns
Hello,
I found this post User Provisioning API example script
about csv .
If you can you can to try it.
If is working write some steps how you tested it.