[Solved] Create user with occ problem with password

Hello !

First of all, sorry for my bad english.
So i want to create user from csv file.
But i have a problem with the password and the occ commands.
I want to set password via a variable, how can i do this ?

Here my script, i hope you will understand what i want to do :

 cat testutil.csv | while read line
 do
    user=$(echo $line | awk -F";" '{print $1}')
    password=$(echo $line | awk -F";" '{print $2}')
    sudo -u www-data php /var/www/nextcloud/occ user:add --password-from-env --display- name="$user" --group="group1" $user

done

How can i set the password via $password ?

Thanks

ps my csv file is like :
user1;password1
user2;password2
etc…

Hi @Mr_D

The parameter “–password-from-env” reads the environment variable OC_PASS. So you could set this ENV before calling the add command:

cat testutil.csv | while read line
 do
    user=$(echo $line | awk -F";" '{print $1}')
    export OC_PASS=$(echo $line | awk -F";" '{print $2}')
    sudo -u www-data php /var/www/nextcloud/occ user:add --password-from-env --display- name="$user" --group="group1" $user

Not sure if user:settings or user:resetpassword is another possibility to modify the password:
php /var/www/nextcloud/occ user:setting
php /var/www/nextcloud/occ user:resetpassword

haven’t experimented with these and don’t know how they work in details :smiley:

@Schmu Hi !

You’re right, this is the solution !
Thanks you !

1 Like

Glad it helped :slight_smile:
Can you mark my answer as solution?