cron in ubuntu

cron in ubuntu

by Erik Ringmar -
Number of replies: 18
Dear all,

I can't run a cron script on my server since my host doesn't permit it.  Sigh ... However, it is possible to run the cron on a PC.  I did it for Windows, but now I've moved over to Ubuntu and I'm lost again.  Any ideas?

cheers,

Erik
Average of ratings: -
In reply to Erik Ringmar

Re: cron in ubuntu

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Sure! Ubuntu (like every other Unix/Linux in the world) ships cron by default.

Just open a command line terminal, and type:

    crontab -l > some-file-name

Then edit that file and add a like like this to it:

    */5 * * * * wget -q -O /dev/null http://your.moodle.site/moodle/admin/cron.php

The save the file and execute:

    crontab some-file-name

That should do it.

Saludos. Iñaki
In reply to Erik Ringmar

Re: cron in ubuntu

by John Ridge -
My server would also not allow cron scripts.
On Mac OS X I had problems with wget, but the following terminal line works:
curl -q -o dev/null http://mysite.wot/moodle/admin/cron.php

cheers

john
In reply to John Ridge

Re: cron in ubuntu

by Erik Ringmar -
Dear both,

Thanks a lot.  This is great.  I've followed your instructions and it seems to work.  But will the cron just keep on running in the background even if I close the terminal?  How to stop it?  And what does it do?  -- runs the cron job every 5 minutes I presume.

cheers,

Erik
In reply to Erik Ringmar

Re: cron in ubuntu

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It does run in the background. To stop it, you have to remove the line you just added (you can run several jobs in the same cron tab, with different schedules, different commands, and so on). As you presume, it runs the cron job every 5 minutes (that's what '*/5' means).

Saludos. Iñaki.
In reply to John Ridge

Re: cron in ubuntu

by Peter Campbell -
John - How do you get this Mac OS X terminal line command to keep repeating every five minutes? I tried it and it seemed to work, but it only executed once.

Cheers,

Peter
In reply to Peter Campbell

Re: cron in ubuntu

by Rahim Virani -
Hi, Im not John but I hope this helps

farmiliarize yourself with vi,

type 'crontab -e'
insert the following line

*/5 * * * * wget -q -O /dev/null http://yourserver/moodleinstallation/admin/cron.php

write and quit

Hope this helps.
In reply to Rahim Virani

Re: cron in ubuntu

by Peter Campbell -
Hi, Rahim. I tried this and got this error:

E486: Pattern not found: 5 * * * * wget -q -O

Any ideas?

Thanks.
In reply to Peter Campbell

Re: cron in ubuntu

by Peter Campbell -
Actually, I just found out how to fix this, but now I am wondering: how do I know of this is working? Is there something I can enter in the Terminal window that will tell me that the cron job is running correctly?

Peter
In reply to Peter Campbell

Re: cron in ubuntu

by Fiona MacAlister -

Hi Peter

Can you please let us know how you fixed it?  I'm also running Moodle on Ubuntu and have had continuous problems trying to get it to work.

Up to now I've had to run cron manually from Moodle Admin.

Thanks.

Fiona

In reply to Peter Campbell

Re: cron in ubuntu

by Markus Översti -
In ubuntu server command 'tail -f /var/log/apache2/access.log|grep cron.php' (without guotes) gets a line every 5 minutes or so. (If you have apache2, in apache 1.3 I guess you must remove 2 in previous command)

And of course you can take the -q option out of wget in cron, so it outputs to mail (to you?) whatever there is to output.
In reply to Markus Översti

cron in Mac OS X (was Re: cron in ubuntu)

by Peter Campbell -
I changed the subject line because it was confusing.

I did as Rahim suggested:

I typed "crontab -e" (no quotes)
Then I typed "i" (again, no quotes) to insert the following line

*/5 * * * * wget -q -O /dev/null http://yourserver/moodle/admin/cron.php

It seemed to work. But how do I know it worked? Is there a command I can use to confirm the success or failure? I am not a UNIX/command line kind of person! Give me a GUI or give me death! Sorry if this is a really basic question.

Peter
In reply to Peter Campbell

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Rahim Virani -
Hi Peter,

There are two ways that you can check.

check the log file of your web server for admin/cron.php
or, go into moodle goto the Administration, I believe if it hasnt been accessed for a while, then moodle will notify you, in addition (I hope you have moodle backup your courses). If your backups are running (check the dates on them) then you have confirmed that cron.php is being invoked.

Hope this helps,

R.
In reply to Rahim Virani

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Peter Campbell -
Hi, Rahim. I don't have access to the log files on my server (I'm using a shared server and don't have root access).

I checked the Moodle admin page and -- unfortunately -- the cron did not run properly.

Peter
In reply to Peter Campbell

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Markus Översti -
Try crontab without -q option. Then you will get output of that command to your account in ubuntu-server.

*/5 * * * * wget http://yourserver/moodle/admin/cron.php

(If it is not yours email-server, then you can try mail-command to read yours email, or put .forward file [which has yours real email-address] to yours homedirectory)
In reply to Peter Campbell

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Iván Fuentes -
Peter,

On MacOS X in the user that you install Moodle there is a "local" e-mail account, every time the cron is execute, a mail message with the result on the cron is generate, you can check it, on the terminal typing:
"$ mail" (no quotes)
you will get a list of messages, and a "&" sign, waiting the number of the message you want to check. There is one way to check it via GUI, the link is http://www.osxfaq.com/ReaderReports/Receiving_Daily_System/index.ws

Goog Luck
One Last question: What version of Moodle on Mac do you use?
In reply to Iván Fuentes

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Peter Campbell -
Ivan - thanks for this. I checked the "local" e-mail in Terminal. I saw that the cron job was running every 5 minutes - hurray!

BUT - I got this error message:

/bin/sh: line 1: wget: command not found

Originally, I opened Terminal and typed "crontab -e" (no quotes)
Then I typed "i" (again, no quotes) to insert the following line

*/5 * * * * wget -q -O /dev/null http://yourserver/moodle/admin/cron.php

So wget is not recognized on the Mac?

Peter

In reply to Peter Campbell

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Robert Brenstein -
Yes, no wget on OS X. Use curl instead. See, for example

http://moodle.org/mod/forum/discuss.php?d=46944#215214
In reply to Robert Brenstein

Re: cron in Mac OS X (was Re: cron in ubuntu)

by Peter Campbell -
Joyous day! It works! It works!

Thanks to all of you for helping out.

Peter