https://www.raphael-muench.de/docs/nextcloud.html

Nextcloud



Add users in nextcloud automatically



Add users in nextcloud automatically

This is a very simple bash script for adding new users in nextcloud automatically !
It was tested successfully with nextcloud 15.0.4 and Debian 9.
It uses a csv which must have the following syntax:
‘username’; ‘User Display Name’; ‘User_group’ ; ’ '; ’ '; ’ '; ‘user_email’;


Download here => import_users.sh


#!/bin/bash

# (C) Raphael Muench 2019

var_datum=$(date +"%Y%m%d")
var_user_file="users.txt"
var_apache_user=www-data
var_path_nextcloud=/var/www/html/nextcloud
var_result_file="${var_datum}_user_create.txt"
while read -r line
do
var_password=$(pwgen 12 -c -n -N 1)
set -e
export OC_PASS="cvjmgraben"
var_username=$(echo "${line}" | cut -d";" -f1)
var_name=$(echo "${line}" | cut -d";" -f2)
var_group=$(echo "${line}" | cut -d";" -f3)
var_email=$(echo "${line}" | cut -d";" -f7)

# Add user
su -s /bin/sh ${var_apache_user} -c "php ${var_path_nextcloud}/occ user:add --password-from-env --group='${var_group}' --display-name='${var_name}' ${var_username}"

# Configure Quota
su -s /bin/sh ${var_apache_user} -c "php ${var_path_nextcloud}/occ user:setting $var_username} files quota '0b'"

# Configure email address
su -s /bin/sh ${var_apache_user} -c "php ${var_path_nextcloud}/occ user:setting ${var_username} settings email ${var_email}"


echo "User ${var_username} was created with password ${var_password}" >> "${var_result_file}"
done < $var_user_file




Copyright (c) 2017, 2018, 2019 Raphael Münch, last change: 2019-02-18
Valid HTML 5.0