External database authentication - users created at login, but not via cron

External database authentication - users created at login, but not via cron

by Robert Norman -
Number of replies: 3
Can't figure this one out.


I have Moodle 3.2 installed on a Ubuntu. I've configured external database enrollments and authentication. Courses are being created, enrollments are fine, but users only get created when they log in for the first time, not when the cron job runs. 


I've read this page dozens of times, but I can't figure out what I'm doing wrong, and after several pages of search results, I can't find a post that has my same problem. I have my cron job set up, and it's definitely running, because users do get created--but only after they attempt to login for the first time. 


Here is my cron job:

*/2 * * * * sudo -u www-data /usr/bin/php /var/www/html/moodle/auth/db/cli/sync_users.php -v


PHP: 7.0.13

Apache 2.4.18

Average of ratings: -
In reply to Robert Norman

Re: External database authentication - users created at login, but not via cron

by Joost Elshoff -
Picture of Particularly helpful Moodlers Picture of Testers

Hi Robert,

Did you read the first lines of the page as well? It says:

'This method uses an external database table to check whether a given username and password is valid. If the user does not currently exist in Moodle a new account will be created and their information copied from the external database.'

And this is exactly what you describe. The external database authentication does not synchronise user data via cron, but checks whether the user credentials are correct in the external database. This check comes from the authentication bit, when it basically verifies if a user is who he says he is. 

It does not create a full database/table synchronisation over cron of all of the users in your external database. There are other ways of getting that done, mostly through API's and webservices if I'm correct.

In reply to Joost Elshoff

Re: External database authentication - users created at login, but not via cron

by Robert Norman -

The external database authentication actually does create new users. I know because I've gotten it working now.

I modified my cronjob to take out the user:

*/20 * * * * /usr/bin/php /var/www/html/moodle/auth/db/cli/sync_users.php -v


Now users are being created from the external database every 20 minutes. 

In reply to Robert Norman

Re: External database authentication - users created at login, but not via cron

by Ezequias Silva -


Robert, I'm going through the same problem. How did you create the courses in moodle? 


 I'm running my cron: php /www/moodle_ensino/enrol/database/cli/sync.php -v to create the courses. 


This is making me sleepy.