Moodle cron job failing

Category: Moodle

JohnJa
Asked:
2013-10-28 3:56 pm EST

Hits: 989
I have been unable to get my daily cron job for a Moodle installation working. I need to call this script each night:
https://www.ligminchalearning.com/crs2/admin/cron.php

Here's the support article from Moodle on how to configure the cron:
http://docs.moodle.org/25/en/Cron_with_Unix_or_Linux

I found the recommended wget method is blocked on your system, so I have tried curl, but it hasn't run properly yet. I have tried this a few different ways, and just set it to:
/usr/bin/curl https://www.ligminchalearning.com/crs2/admin/cron.php -o /dev/null/ -silent

Should the above work, or do you have a different approach you would suggest?

Thanks!
John Jackson

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

JacobIMH
Staff
9,968 Points
2013-10-28 4:17 pm EST
Hello John, and thank you for your question.

We have a guide about how to run a cron job that mentions wget is disabled on all our shared servers, you could instead use the curl command, but need to be sure to define a User-Agent so that it is not blocked by ModSecurity rules on the server.

In your case, the final command would need to look something like:

/usr/bin/curl --user-agent cPanel-Cron https://www.ligminchalearning.com/crs2/admin/cron.php -o /dev/null/ -silent


Now if you take a look in your website's access-logs, instead of just saying curl/7.15.5 as the User-Agent, it would instead read cPanel-Cron. You can have it say whatever you'd like, just so long as it is defined.

Let us know if you had any other questions at all.

- Jacob

You must login before you can post a comment about this answer.

Jacob,
Thanks for the quick response. I'ved edited my cron file and we'll see if it runs properly tonight.

I suggest adding some examples to the documentation page you refer to, so users can see exactly how to implement the curl and lynx commands.
JohnJa
51 Points
2013-10-28 5:19 pm EST
Hello John,

No problem, I went ahead and updated the cron article with an example command as you suggested. Thanks for that!

- Jacob
JacobIMH
9,968 Points
Staff
2013-10-28 6:13 pm EST
this still is not working for me. I was getting no output via email when the cron job ran, so I turned off the -silent param. Then I got the message below via the email output, but there is no indication that the cron job was successful.
John
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:06 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:07 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:08 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:10 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:11 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:12 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:13 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:14 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:15 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:16 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:17 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:18 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:19 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:20 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:21 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:22 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:23 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:24 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:25 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:26 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:27 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:28 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:29 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:30 --:--:-- 0Warning: Failed to create the file /dev/null/

0 0 0 0 0 0 0 0 --:--:-- 0:00:31 --:--:-- 0
curl: (23) Failed writing body
JohnJa
51 Points
2013-11-08 8:08 pm EST
Hello John,

It looks like your Moodle cron.php script wasn't sucessfully completing in a timely manner according to that output, as what you're getting via email is showing that it essentially ran for 31 seconds but didn't download any data. It also encounters an issue with the -o /dev/null part of the command saying that it can't create that file to store the output in.

I would suggest instead using this command which I just tested on your account which appears to work properly. You'd want to replace userna5 with your actual cPanel username:

/usr/bin/curl --user-agent cPanel-Cron https://www.ligminchalearning.com/crs2/admin/cron.php > /home/userna5/cron.log


Here is the output that was stored in the /home/userna5/cron.log log once I ran it for you one time:

Cron script completed correctly
Cron completed at 11:05:39. Memory used 99MB.
Execution took 79.401971 seconds


You should be able to check that cron.log file a few minutes after you scheduled your cron job to run, and if there were any issues it should be logged there.

Please let us know if you're still having issues with this.

- Jacob
JacobIMH
9,968 Points
Staff
2013-11-11 3:15 pm EST
Like this Question?

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!