This:
sudo crontab -u www-data -e
Added the following line to the crontab file:
*/1 * * * * /usr/bin/php /var/www/mywebsite/moodle/admin/cli/cron.php > /var/log/moodle-cron.log
Saved and exited the text editor.
Sets up the cron job.
To check it from command line ... I'll break apart the whole command and provide comments in ()
/usr/bin/php (has to find php-cli)
/var/www/mywebsite/moodle/admin/cli/cron.php
(is the full path to the cron.php script to run)
> /var/log/moodle-cron.log
Is the redirect of the output the cron.php file to a log file which has to exist.
To execute the above ... type the whole thing:
/usr/bin/php /var/www/mywebsite/moodle/admin/cli/cron.php > /var/log/moodle-cron.log
Since you are redirecting to a log file, the above will NOT ... repeat NOT ... display anything. There will be a pause ... indicating the script is running, and then one is presented with a blank command prompt again.
TO SEE IF IT LOGGED DO THIS:
cat /var/log/moodle-cron.log
Now a test ... this is a real example:
On a server I have that has 3 instances of moodle, the cron jobs for each of them redirects to a log file for the site name:
in /var/log/ I have:
m44sb-cron.log - site is https://mysite/m44sb/
mdlandcli-cron.log - site is https://mysite/mdlandcli/
mdlsamples-cron.log - site is https://mysite/mdlsamples/
To watch just the m44sb site cron log:
tail -f /var/log/m44sb-cron.log
The command above will 'watch' that log file and when it changes, I'll see
the changes take place.
I know the cron job is running because the log file changes.
If I wait there still in tail -f /var/log/m44sb-cron.log
I can see it execute each time it executes.
To get out of tail, [CTRL][C]
To test without logging:
/usr/bin/php /var/www/html/m44sb/admin/cli/cron.php [ENTER]
When that finishes and I want to run it again ... UP Arrow on keyboard ...
my previous command is put on the command line for me.
PRESS ENTER and it runs again.
'SoS', Ken