Hello,
openedx plateforme was recently installed in my school with tutor method,
the next step is to bulk add teachers and students to the plateforme, how to do it?
in the page http://myopenedx.mydomain/admin there is no way to do it, only by creating users manualy one by one and it’s not possible because of the huge number of users( thousends) .
can you give me the steps to follow ?
thank you
there’s a few ways to do it, you could use the API if you’re familiar with using API access.
You can also get users to self register and then you go edit users staff/superuser status.
The way I would do it (I’m not implying that this is the best way to do it, just a method I came up with) is with a for loop
to loop through a list of users to add and have the loop run this for each user:
tutor local createuser --staff --superuser <name> <email> -p <password>
--staff
will be for teachers and --superuser
would be a super admin
So in a CSV file you can have a list of: username,email,password,staff,superuser
Example: users.csv
username,email,password,staff,superuser
testuser1,test1@domain.tld,password123,1,0 (staff user)
testuser2,test2@domain.tld,password123,0,1 (super user)
testuser3,test3@domain.tld,password123,1,1 (staff + super user)
testuser4,test4@domain.tld,password123,0,0 (student)
*this line should be left as blank (empty newline)*
This script below (BASH for Linux, if you’re using another backend then none of this will really apply to you, but the concept can be implemented in other scripting languages) will iterate through each user and run the command tutor local do createuser --staff testuser1 test1@domain.tld -p password123
Save this script as bulkaddusers.sh
and run chmod +x bulkaddusers.sh
to set it as executable, save your CSV file in the same location and run ./bulkaddusers.sh
to start the script
#!/bin/bash
# Assuming your CSV file is named users.csv
CSV_FILE="users.csv"
# Read the CSV file line by line into an array
mapfile -t lines < "$CSV_FILE"
# Iterate over each line
for line in "${lines[@]:1}"; do
# Split the line into fields
IFS=',' read -r username email password staff superuser <<< "$line"
# Trim leading and trailing whitespace from each field
username=$(echo "$username" | tr -d '[:space:]')
email=$(echo "$email" | tr -d '[:space:]')
password=$(echo "$password" | tr -d '[:space:]')
staff=$(echo "$staff" | tr -d '[:space:]')
superuser=$(echo "$superuser" | tr -d '[:space:]')
# Build the command string based on staff and superuser values
command="tutor local do createuser"
if [ "$staff" -eq 1 ]; then
command+=" --staff"
fi
if [ "$superuser" -eq 1 ]; then
command+=" --superuser"
fi
command+=" $username $email -p $password"
# Print debug information
echo "Executing command: $command"
# Execute the command and capture the output
output=$(eval "$command" 2>&1)
# Check the exit code
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Command finished successfully for $username"
else
echo "Error executing command for $username. Exit code: $exit_code"
echo "Output: $output"
fi
# Sleep for a short duration to allow the previous command to finish
sleep 2
done
# Exit the script
exit 0
here’s the output when I run the script:
tutor@tutor-beta:~$ ./bulkaddusers.sh
Executing command: tutor local do createuser --staff testuser1 test1@domain.tld -p password123
Command finished successfully for testuser1
Executing command: tutor local do createuser --superuser testuser2 test2@domain.tld -p password123
Command finished successfully for testuser2
Executing command: tutor local do createuser --staff --superuser testuser3 test3@domain.tld -p password123
Command finished successfully for testuser3
Executing command: tutor local do createuser testuser4 test4@domain.tld -p password123
Command finished successfully for testuser4
Hope this is useful to you
Sample files attached for your convenience:
bulkaddusers.zip (947 Bytes)
thanks a lot joel.edwards,
it worked for me, your reply is just very helpfull;
thank you.
Fantastic, glad you found it useful!