Help for a script to create users from a txt file

Please help us by providing the following info. Before posting please also check the pinned "Known issues" threads and make sure that you're running the latest available version for your oC release:

Steps to reproduce

Expected behaviour
Tell us what should happen

Actual behaviour
Tell us what happens instead

Server configuration
Operating system:Centos
Web server:apache
PHP version:5.6
ownCloud version (see ownCloud admin page):9.1.3
Updated from an older ownCloud or fresh install:fresh
Special configuration (external storage, external authentication, reverse proxy, server-side-encryption):


I'm stuck with a task that seem basic. I need to create for a special temporary need 380 local accounts on an Owncloud 9.1 server.
This account are all in a accounts.txt file with a ; separator like this

My account 1;login1;password1
My account 2;login2;password2

Very simple, the first field is the display name, the second the uid/login, the third the password.

I follow instruction here
But my shell script does not work, I've always an error

First try with a shell script like this:

#! /bin/bash

while IFS=";" read display user pass
export OC_PASS=$pass

#echo -e "$display :\n\
# UID :\t $user\n\
# password :\t $pass\n\n"

**sudo -u apache php /var/www/html/owncloud/occ user:add --password-from-env --display-name="$display" --group="OWNCLOUD AG EXT" $user**

done < /root/accounts.txt

The result is

--password-from-env given, but OC_PASS is empty!

If I just display the fields (see the commented line), it's working.

So I tried the following according to the documentation (su -s)

#! /bin/bash

while IFS=";" read display user pass

export OC_PASS=$pass

#echo -e "$display :\n\
# UID :\t $user\n\
# password :\t $pass\n\n"

**su -s /bin/sh apache -c "php /var/www/html/owncloud/occ user:add --password-from-env --display-name="$display" --group="OWNCLOUD AG EXT" $user"**

done < /root/accounts.txt

In this case, I have

Not enough arguments (missing: "uid").

If someone have already created a script like this, you are welcome. In both case, it seems to be a variable not set but I don't know how to keep them. May be it's just a stupid thing I miss...


I will answer to myself :
sudo -Eu did the trick, it was a problem af environnement variables preservation. The command that work is :

sudo -Eu apache php /var/www/html/owncloud/occ user:add --password-from-env --display-name="$display" --group="mygroup" $user

1 Like

Iā€™m having trouble getting the script to work. Are the hashtags and stars meant to be there