Hinweis: Sie sind auf den Seiten der Moodle 2.4 Dokumentation. Die Dokumentation der aktuellsten Moodle-Version finden Sie hier: Cron-Job.

Cron-Job: Unterschied zwischen den Versionen

Aus MoodleDocs
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
{{Zum Übersetzen}}
{{Zum Übersetzen}}
Siehe [[:en:Cron]]


{{Installation}}
{{Installation}}


Einige Module von Moodle prüfen regelmäßig, ob bestimmte Aufgaben ausgeführt werden müssen. Moodle überprüft z.B. ob es im Forum neue Einträge gibt, die per Email an Nutzer versandt werden müssen.
Der '''Cron-Prozess''' von Moodle ist ein PHP-Skript, das zum Moodle-Standardpaket gehört, und das regelmäßig im Hintergrund ausgeführt werden muss. Das Skript führt in verschiedenen Zeitabständen verschiedene Aufgaben aus, z.B. E-Mails-versenden, Moodle-Berichte aktualisieren, RSS-Feeds aktualisieren , Aktivitätenabschluss kennzeichnen, Forumsbeiträge veröffentlichen. Da zu verschiedenen Aufgaben verschiedene Zeitintervalle gehören, werden nicht alle Aufgaben jedes Mal ausgeführt, wenn das Cron-Skript gestartet wird.
 
'''Wichtig''': Sie müssen den Cron-Prozess unbedingt aufsetzen, andernfalls funktioniert Ihre Moodle-Site '''nicht''' richtig.
 
Um das Moodle-Cron-Skript in regelmäßigen Abständen auszuführen, wird ein spezielles Programm (typischerweise <code>cron</code>) verwendet.
 
Einen Cron-Job einrichten bedeutet im wesentlichen eine Zeile in die Liste der Cron-Prozesse auf Ihrem Server einzutragen. Auf Unix-basierten Systemen ist diese Liste eine Datei ''crontab'', die alle Nutzer/innen des Servers haben.
 
==Allgemeines==
Das Aufsetzen eines Cron-Prozesses erfordert zwei Schritte:
#Das richtige Kommando identifizieren, das ausgeführt werden muss.
#Den richtigen Platz auf Ihrem Server finden, wo das Kommando eingetragen werden muss.
 
===Das richtige Kommando identifizieren===
In Moodle gibt es zwei Möglichkeiten, das Cron-Skript auszuführen:
# CLI-Skript (CLI = command line interpreter, Kommandozeileninterpreter): Der Pfad zu diesem Skript ist ''/path_to_moodle/admin/cli/cron.php''. Dieses Skript muss von einem PHP CLI Programm auf Ihrem Server ausgeführt werden, z.B. durch folgendes Kommando:
<code>/usr/bin/php /path/to/moodle/admin/cli/cron.php</code>
# Webbasiertes Skript: Dieses Skript muss im Webbrowser aufgerufen werden, der Zugriff erfolgt über die URL <nowiki><code>http://Ihre.Moodle.Site/admin/cron.php</code></nowiki>. Sie können einen kommandozeilen-basierten Webbrowser verwenden (z.B. <code>wget</code>), d.h. das Kommando könnte z.B. lauten:
<code>/usr/bin/wget http://Ihre.Moodle.Site/admin/cron.php</code>   
Der Vorteil dieses Kommandos besteht darin, dass es von überall ausgeführt werden kann, also nicht notwendigerweise von Ihrem Moodle-Server aus (auf den Sie evtl. gar keinen Zugriff haben), sondern von irgend einem Server aus, auf den Sie zugreifen dürfen.
 
===Den richtigen Platz auf dem Server finden===


==Cron-Job-Skript==
==Cron-Job-Skript==
Zeile 267: Zeile 287:
Usually, the "crontab -e" command will put you into the 'vi' editor. You enter "insert mode" by pressing "i", then type in the line as above, then exit insert mode by pressing ESC. You save and exit by typing ":wq", or quit without saving using ":q!" (without the quotes). Here is an [http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html intro] to the 'vi' editor.
Usually, the "crontab -e" command will put you into the 'vi' editor. You enter "insert mode" by pressing "i", then type in the line as above, then exit insert mode by pressing ESC. You save and exit by typing ":wq", or quit without saving using ":q!" (without the quotes). Here is an [http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html intro] to the 'vi' editor.


==See also==
==Siehe auch==
* [http://de.wikipedia.org/wiki/Cron Wikipedia-Artikel über Cron]


Using Moodle forum discussions:
Diskussionsbeiträge im Kurs ''Using Moodle'' auf moodle.org:
*[http://moodle.org/mod/forum/discuss.php?d=41827 Cron - can someone give me a quick confirmation of function?]
*[http://moodle.org/mod/forum/discuss.php?d=41827 Cron - can someone give me a quick confirmation of function?]
*[http://moodle.org/mod/forum/discuss.php?d=97684 Cronjob Question]
*[http://moodle.org/mod/forum/discuss.php?d=97684 Cronjob Question]
Zeile 275: Zeile 296:
*[http://moodle.org/mod/forum/discuss.php?d=117168 Visibility of cron.php]
*[http://moodle.org/mod/forum/discuss.php?d=117168 Visibility of cron.php]
*[http://moodle.org/mod/forum/discuss.php?d=139263#p609060 How to log the output of a Scheduled Task on Windows] - this discussion explains a nice trick that can be very useful when you are experiencing problems with your Windows Scheduled Task and you need to log the output of the Scheduled Task to a log file.
*[http://moodle.org/mod/forum/discuss.php?d=139263#p609060 How to log the output of a Scheduled Task on Windows] - this discussion explains a nice trick that can be very useful when you are experiencing problems with your Windows Scheduled Task and you need to log the output of the Scheduled Task to a log file.
{{Credits}} [https://docs.moodle.org/19/de/Cron-Job]
{{Credits}} [https://docs.moodle.org/19/de/Cron-Job]



Version vom 24. Mai 2012, 11:27 Uhr

Baustelle.png Diese Seite ist noch nicht vollständig übersetzt.



Der Cron-Prozess von Moodle ist ein PHP-Skript, das zum Moodle-Standardpaket gehört, und das regelmäßig im Hintergrund ausgeführt werden muss. Das Skript führt in verschiedenen Zeitabständen verschiedene Aufgaben aus, z.B. E-Mails-versenden, Moodle-Berichte aktualisieren, RSS-Feeds aktualisieren , Aktivitätenabschluss kennzeichnen, Forumsbeiträge veröffentlichen. Da zu verschiedenen Aufgaben verschiedene Zeitintervalle gehören, werden nicht alle Aufgaben jedes Mal ausgeführt, wenn das Cron-Skript gestartet wird.

Wichtig: Sie müssen den Cron-Prozess unbedingt aufsetzen, andernfalls funktioniert Ihre Moodle-Site nicht richtig.

Um das Moodle-Cron-Skript in regelmäßigen Abständen auszuführen, wird ein spezielles Programm (typischerweise cron) verwendet.

Einen Cron-Job einrichten bedeutet im wesentlichen eine Zeile in die Liste der Cron-Prozesse auf Ihrem Server einzutragen. Auf Unix-basierten Systemen ist diese Liste eine Datei crontab, die alle Nutzer/innen des Servers haben.

Allgemeines

Das Aufsetzen eines Cron-Prozesses erfordert zwei Schritte:

  1. Das richtige Kommando identifizieren, das ausgeführt werden muss.
  2. Den richtigen Platz auf Ihrem Server finden, wo das Kommando eingetragen werden muss.

Das richtige Kommando identifizieren

In Moodle gibt es zwei Möglichkeiten, das Cron-Skript auszuführen:

  1. CLI-Skript (CLI = command line interpreter, Kommandozeileninterpreter): Der Pfad zu diesem Skript ist /path_to_moodle/admin/cli/cron.php. Dieses Skript muss von einem PHP CLI Programm auf Ihrem Server ausgeführt werden, z.B. durch folgendes Kommando:

/usr/bin/php /path/to/moodle/admin/cli/cron.php

  1. Webbasiertes Skript: Dieses Skript muss im Webbrowser aufgerufen werden, der Zugriff erfolgt über die URL <code>http://Ihre.Moodle.Site/admin/cron.php</code>. Sie können einen kommandozeilen-basierten Webbrowser verwenden (z.B. wget), d.h. das Kommando könnte z.B. lauten:

/usr/bin/wget http://Ihre.Moodle.Site/admin/cron.php Der Vorteil dieses Kommandos besteht darin, dass es von überall ausgeführt werden kann, also nicht notwendigerweise von Ihrem Moodle-Server aus (auf den Sie evtl. gar keinen Zugriff haben), sondern von irgend einem Server aus, auf den Sie zugreifen dürfen.

Den richtigen Platz auf dem Server finden

Cron-Job-Skript

Das Skript, das all diese Vorgänge steuert, finden Sie im Admin-Verzeichnis und heißt cron.php. Diese Datei läuft nicht von alleine. Sie müssen einen Mechanismus einrichten, der die Datei z.B. alle fünf Minuten ausführt. Dazu ist es erforderlich, dass ein "Impuls" für jedes Modul ausgelöst wird.

Der Auslöser dieses Impulses muss nicht von dem Server erfolgen auf dem Moodle installiert ist.. Wenn Sie auf diesem Server keine Cron-Jobs ausführen können, kann dies von einem anderen Server ausgelöst oder von Ihrem PC gestartet werden. Es ist lediglich nötig, die Datei cron.php alle fünf Minuten aufzurufen.

Testen Sie zuerst, ob die Datei funktioniert. Rufen Sie sie mit Ihrem Browser auf:

http://example.com/moodle/admin/cron.php

Nehmen Sie nun einige Einstellungen vor: Aufruf des Skripts von der Kommandozeile

Rufen Sie die Datei wie zuvor auf. Nehmen Sie dazu z.B. den Unix-Befehl 'wget':

wget -q -O /dev/null http://example.com/moodle/admin/cron.php

In diesem Beispiel wird das Ergebnis abgelegt (nach /dev/null).

Das gleiche mit lynx:

lynx -dump http://example.com/moodle/admin/cron.php > /dev/null

Alternativ können Sie eine separate PHP-Version nutzen, die über die Kommandozeile gesteuert wird. Der Vorteil dieser Variante ist, dass in den Log-Dateien des Web-Servers der Aufruf von cron.php nicht ständig protokolliert wird. Der Nachteil dieser Variante besteht darin, dass Sie einen Zugang zur Kommando-Zeile der PHP-Version benötigen.

/opt/bin/php /web/moodle/admin/cli/cron.php

( Windows) C:\apache\php\php.exe C:\apache\htdocs\moodle\admin\cron.php

Manuelles Ausführen über den Administrationsbereich

Ist das Script seit 24h nicht ausgeführt worden, so wird im Administrationsbereich der moodle-Seite darauf hingewiesen. In diesem Fall können Sie einfach dem Link folgen um den Job auszuführen.


Automatische Ausführung des Skripts alle 5 Minuten

Bei UNIX- Systemen: Use cron. Passen Sie ihre Einstellungen für Cron- Jobs über die Komandozeile mit folgendem Befehl an "crontab -e" und fügen Sie folgende Zeile hinzu:

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

Bei Windows-Systemen: Der einfachste Weg ist hier mein Programm zu benutzen, moodle-cron-for-windows.zip wodurch die Anpassungen ganz einfach sind. Sie können alternativ dazu, die in Windows enthaltene Funktion "Scheduled Tasks" benutzen.

Bei Web Hosting Services

Die Oberflächedes Web Host Services bietet Ihnen die Möglichkeit, einen Cron Job einzurichten. Z.B. Cpanel Systeme: Hier gibt es einen Button "Cron jobs". Geben Sie hier die folgenden Unix-Befehle ein.

Kommando-Zeile von Unix nutzen Es gibt verschiedene Kommandozeilenprogramme, die Sie aufrufen können. Auf Ihrem Server sind vielleicht nicht alle verfügbar.

Z.B. das Unix-Utility 'wget':

wget -q -O /dev/null http://example.com/moodle/admin/cron.php

In diesem Beispiel wird das Ergebnis nicht aufbewahrt (to /dev/null).

Das gleiche unter Lynx:

lynx -dump http://example.com/moodle/admin/cron.php > /dev/null

Alternativ können Sie eine standalone Version von PHP nutzen, die kompiliert in der Kommandozeile läuft. Der Vorteil liegt darin, dass der Webserver nicht unnötig beansprucht wird. Der Nachteil liegt darin, dass Sie per Kommandozeile Zugang zu PHP benötigen.

/opt/bin/php /web/moodle/admin/cron.php

Cron-Service Ort und Zeit

Die Maschine, die Cron ausführt, muss nicht die Selbe sein, auf der Moodle läuft! Wenn Sie zum Beispiel einen eingeschränkten Webhoster haben, der keinen Cron-Service unterstützt, dann entscheiden Sie sich eventuell dafür, Cron auf einem anderen Server oder auf Ihrem eigenen Computer laufen zu lassen. Das Wichtigste ist, dass die cron.php-Datei regelmäßig aufgerufen wird.

Das Script benötigt nicht zu viel Systemressourcen, man kann gewöhnlich mit etwa 5 Minuten Dauer rechnen, aber falls Sie sich nicht sicher sind, ob Ihr Server das schafft, können Sie die Zeitdauer auch auf 15 oder sogar 30 Minuten erhöhen. Allerdings ist es ratsam, dass Sie die Dauer nicht zu lange einstellen, da ansonsten andere Aktivitäten (z. B. Versand von E-Mails) dadurch beeinträchtigt werden können, weil Sie auf die Beendigung des Scripts warten müssen.


Cron und manuelle Einstellungen testen

Testen Sie zuerst, ob das Script läuft, wenn Sie es direkt über Ihren Browser ausführen: http://example.com/moodle/admin/cron.php

Wenn Cron über die Kommandozeile von irgendeinem Nutzer, der über Ihr Moodle eingeloggt ist, ausgeführt wird, wird es zeitweise Administrationsrechte erstellen, um sich selbst auszuführen und danach den Benutzer auszuloggen. Sie können die Kommandozeile für Cron deaktivieren, in dem Sie sie im entsprechenden Abschnitt in der cron.php-Datei deaktivieren.

Jetzt müssen Sie einstellen, dass das Script regelmäßig automatisch ausgeführt wird.

Cron unter Windows einrichten

Es gibt verschiedene Möglichkeiten die cron.php-Datei unter Windows einzustellen:

  • Benutzen Sie das Moodle Cron Paket. Das kleine Paket zu benutzenMoodleCron-Setup.exe, macht alles sehr einfach, da es einen kleinen Windows-Service installiert, den Sie lediglich ausführen müssen.
  • Benutzen Sie eine geplante Aufgabe. Wenn Sie lieber das in Windows integrierte Planungsprogramm benutzen wollen oder Probleme mit dem Moodle Paket haben, können sie wget für windows oder php für die Kommandozeile benutzen und eine geplante Aufgabe einrichten. Sie müssen nur folgende Schritte befolgen:
    • Wählen Sie entweder php.exe/php-win.exe (binäre Kommandozeile) oder wget
Mit derphp.exe oder php-win.exe (für PHP Version 5 oder neuer), welche in Ihrem PHP-Ordner installiert wurde (z. B. C:\php), könnne Sie das Cron-script besser ausführen.
Wenn Sie wget benutzen möchten, müssen Sie sich eine kompilierte Version von wget unter Windows (für ursprünglich GNU WIN32 Ports) unter http://unxutils.sourceforge.net, von Heiko Herolds wget-für-Windows-Seite (http://xoomer.virgilio.it/hherold/) oder von Bart Puypes Seite (http://users.ugent.be/~bpuype/wget/) herunterladen. Wenn Sie Heiko Herolds Paket benutzen, müssen Sie alle DLL-Dateien in Ihren Windows System Ordner unter C:\Windows\system32 kopieren. Außerdem muss die wget.exe-Datei in C:\Windows kopiert werden.
  • Richten Sie einen Scheduled Task (geplante Aufgabe) ein.
- Gehen Sie zu Start >> Control Panel >> Scheduled Tasks >> Add Scheduled Task.
- Klicken Sie auf "Next", um den Assistenten zu starten:
- Drücken Sie auf den "Browse..."(Durchsuchen)-Button, suchen Sie c:\php\php.exe oder c:\windows\wget.exe und klicken Sie anschließend auf "Open"
- Tippen Sie "Moodle Cron" als Name für die Aufgabe ein und wählen Sie "Daily" (täglich) aus. Klicken Sie auf "Next"
- Wählen Sie "12:00 AM" als Anfangszeit, führen Sie die Aufgabe "Every Day" (jeden Tag) aus und wählen Sie das heutige Datum als Startdatum. Klicken Sie auf "Next"
- Geben Sie den Benutzernamen und das Passwort ein, unter denen die Aufgabe laufen soll (es muss kein Administratoraccount sein). Überprüfen Sie, ob Sie das Passwort korrekt eingegeben haben! Klicken Sie anschließend auf "Next"
- Setzen Sie einen Haken bei der Checkbox namens: "Open advanced properties for this task when I click Finish" und klicken Sie auf "Finish".
- Es erscheint ein neues Fenster, schreiben Sie dort unter "Run:" in die Text-Box:
c:\windows\wget.exe -q -O NUL http://my.moodle.site/moodle/admin/cron.php
oder
c:\php\php-win.exe -f c:\moodle\admin\cron.php
Ersetzen Sie "c:\moodle" mit dem Pfad, der zu Ihrem Moodle-Ordner führt oder mit "my.moode.site" mit dem Namen Ihrer Moodle-Seite.

- Klicken Sie auf den "Schedule" Reiter und dort anschließend den "Advanced..."(Erweitert)-Button.
- Setzen Sie einen Haken bei der "Repeat task"(Aufgabe wiederholen)-Checkbox und stellen Sie "Every:"(Alle) auf 5 Minuten und bei "Until:" (Bis) "Duration"(Dauer) ein und tippen Sie dort anschließend "23" Stunden und "59" Minuten ein.
- Klicken Sie auf "OK" und Sie sind fertig.
  • Testen Sie Ihre geplante Aufgabe. Sie können testen, ob Ihre geplante Aufgabe problemlos läuft, indem Sie die rechte Maustaste drücken und "Run" auswählen. Wenn alles korrekt eingestellt wurde, werden Sie bald ein DOS Kommandofenster sehen, während wget/php ausgeführt wird und die Cron-Seite abruft, bis sie erscheint. Wenn Sie den Ordner der geplanten Aufgaben aktualisieren, wird eine Spalte namens Last Run Time erscheinen (sofern Sie die detailierte Ordneransicht ausgewählt haben) If everything is correctly setup, you will briefly see a DOS command window while wget/php executes and fetches the cron page and then it disappears. If you refresh the scheduled tasks folder, you will see the Last Run Time column (in detailed folder view) reflects the current time, and that the Last Result column displays "0x0" (everything went OK). If either of these is different, then you should recheck your setup.
  • Logging cron output. You may want to log the output of the cron script as it executes, in case you see the job is producing errors, backups are not being completed or users are experiencing delays in receiving forum emails. To do this, adjust the command so that it uses the php.exe and stores the output in a file called (for example c:\moodle\admin\cron.log). Here is an example of the php.exe command:
c:\php\php.exe -f c:\moodle\admin\cron.php > c:\moodle\admin\cron.log

If you experience problems logging the output of cron.php to a text file using the above command then read this message by Iñaki Arenaza for an alternative way to log the output of Cron.

Note: In version 2.0 and later the path for running cron.php from the commandline has changed. Use c:\moodle\admin\cli\cron.php

Managing the cron job on Mac OS X with launchd

It's really important to start the cron job every 5 minutes. The cron job assists most of Moodle's modules to perform tasks on a scheduled basis. For example, the discussion forums can only mail out copies of new posts to all subscribers if the cron job tells Moodle to do this.

In Mac OS X 10.5 you will find the system daemon launchd for this service. This daemon offers a standardized interface to any user and all programs started automatically by the system. Please look at http://developer.apple.com/macosx/launchd.html for more informations about the configurations and all parameters.

In our case the service should get the web page http://your-server-address/moodle19/admin/cron.php every 5 minutes. The configuration will be done by the file named moodle4mac.cron.plist which must be placed in the system folder /Library/LaunchDaemons/ ... surely you can use any other file name but it should say something about the function of the service. The extension must be .plist. After any reboot of your Mac server the cron service will start automaticly because the file is placed in the correct system folder.

Use the graphical way

You can use Lingon to add a new daemon plist or to edit one. It produces the same text as you can write in your text editor. http://sourceforge.net/projects/lingon/files/

Datei:macosx-lingon.png

Use a text editor

Please use a text editor to write the needed file. You can open the Terminal and use the system editors vi or pico. But you can also write the text file with any GUI text editor ... I mostly use TextWrangler ... but do NOT take an editor for formatted texts like Microsoft Word or OpenOffice Writer. You must get pure text!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key><false/>
<key>Label</key><string>moodle4mac.cron</string>
<key>ProgramArguments</key>
<array>
     <string>curl</string>
     <string>-s</string>
     <string>http://your-server-address/moodle19/admin/cron.php</string>
</array>
<key>RunAtLoad</key><true />
<key>StartInterval</key><integer>300</integer>
<key>StandardErrorPath</key><string>/dev/null</string>
<key>StandardOutPath</key><string>/dev/null</string>
</dict>
</plist>

The label string must be the same as the file name is but without the extension .plist. Save the text file /Library/LaunchDaemons/moodle4mac.cron.plist. The owner of the file must be set to the system user root. If you use a site with SSL (ie: it has an https:// protocol) you either need to have your SSL certificates listed for use by the CURL utility (see these docs for more details) OR you must use the '-k' switch in addition to the '-s' switch used above; your arguments line would then read: `<string>-s -k</string>`.

That's all, really!

How to start and stop the cron service

You can start the new cron service in the Terminal.

sudo launchctl load /Library/LaunchDaemons/moodle4mac.cron.plist

The following command would stop the service. If you want to activate changes in the cron service you need to unload and then to load the daemon again.

sudo launchctl unload /Library/LaunchDaemons/moodle4mac.cron.plist

Only one service for two servers?

For my server I needed to have a cron service for to instances moodle19 and moodle20 ... no problem ... with the typo moodle[19-20] I will get a cron service for both.

curl -s http://your-server-address/moodle[19-20]/admin/cron.php

To see if the cron service works correctly you should look at the access.log of your web server. The cron.php should be accessed every 5 minutes ... on my server for both Moodle instances moodle19 and moodle20 ... oh yes, it works!!

192.168.0.220 - - [30/Jul/2009:22:10:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 1136
192.168.0.220 - - [30/Jul/2009:22:10:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 1403
192.168.0.220 - - [30/Jul/2009:22:11:18 +0200] "OPTIONS * HTTP/1.0" 200 -
192.168.0.220 - - [30/Jul/2009:22:15:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 735
192.168.0.220 - - [30/Jul/2009:22:15:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 964
192.168.0.220 - - [30/Jul/2009:22:20:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 1136
192.168.0.220 - - [30/Jul/2009:22:20:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 1365

Managing cron on web hosting services

Your web-based control panel may have a web page that allows you to set up a cron service process.

CPanel cron service

If you are using CPanel, login then look for "Advanced" category towards the bottom of the page. Click on Cron Jobs -> Advanced (Unix style). Enter the following for the cron to run every 30 minutes.

Email address for output: emailaddress@mydomain.con
Minute:*/30
Hour:*
Day:*
Month:*
Weekday:* 
Command: wget -q -O /dev/null http://www.mydomain.com/moodle/admin/cron.php

Click Commit Changes. Check your email for the output.

Datei:Cpanel-cron-setup.JPG

Other systems cron service

For other systems, look for a button called "Cron jobs". In there you can put the same sort of Unix commands as listed below.


If you don't have permissions to run the 'wget' command on the server, you can use this php command:

/usr/local/bin/php -q /real/path/to/script/admin/cron.php

For example:

/usr/local/bin/php -q /home/username/public_html/moodle/admin/cron.php

If you don't know what is the real path of your Moodle folder you can use the PHP command realpath.

Another alternative, if you do not have permission to run the 'wget' command, may be to use a curl command.

For example:

curl --silent --compressed http://mydomain.com/moodle/admin/cron.php

Note: In version 2.0 and later the path for running cron.php from the commandline has changed. Use c:\moodle\admin\cli\cron.php

Using a cron command line in Unix

There are different command line programs you can use to call the page from the command line. Not all of them may be available on a given server.

Note: The examples with wget, lynx, and similar are not the same as the "CLI only" cron checkbox, mentioned above (the configuration variable "cronclionly"). wget, lynx, and other similar utilities are Unix command-line HTTP clients, and thus running cron.php in this way is the same as running it in a browser, from Moodle's point of view.

For example, you can use a Unix utility like 'wget':

wget -q -O /dev/null http://example.com/moodle/admin/cron.php

Note in this example that the output is thrown away (to /dev/null).

A number of users of Moodle have found that 'wget' sometimes fails. Especially if you have trouble with email digests not being sent on a daily basis to all users, an alternative command that solves the problem is:

php http://example.com/moodle/admin/cron.php

The same thing using lynx:

lynx -dump http://example.com/moodle/admin/cron.php > /dev/null

Note in this example that the output is thrown away (to /dev/null).

Alternatively, you can use a standalone version of PHP, compiled to be run on the command line. The disadvantage is that you need to have access to a command-line version of php. The advantage is that your web server logs aren't filled with constant requests to cron.php and you can run at a lower I/O and CPU priority.

/opt/bin/php /web/moodle/admin/cli/cron.php

Example command to run at lower priority:

 ionice -c3 -p$$;nice -n 10 /usr/bin/php /moodle/admin/cli/cron.php > /dev/null

Note: In version 2.0 and later the path for running cron.php from the commandline has changed. Use c:\moodle\admin\cli\cron.php

Using the crontab program on Unix

All that Cpanel does is provide a web interface to a Unix utility known as crontab. If you have a command line, you can set up crontab yourself using the command:

crontab -e

and then adding one of the above commands like:

*/30 * * * * wget -q -O /dev/null http://example.com/moodle/admin/cron.php

The first five entries are the times to run values, followed by the command to run. The asterisk is a wildcard, indicating any time. The above example means run the command wget -q -O /dev/null... every 30 minutes (*/30), every hour (*), every day of the month (*), every month (*), every day of the week (*).

The "O" of "-O" is the capital letter not zero, and refers the output file destination, in this case "/dev/null" which is a black hole and discards the output. If you want to see the output of your cron.php then enter its url in your browser.

For beginners, "EDITOR=nano crontab -e" will allow you to edit the crontab using the nano editor. Ubuntu defaults to using the nano editor.

Usually, the "crontab -e" command will put you into the 'vi' editor. You enter "insert mode" by pressing "i", then type in the line as above, then exit insert mode by pressing ESC. You save and exit by typing ":wq", or quit without saving using ":q!" (without the quotes). Here is an intro to the 'vi' editor.

Siehe auch

Diskussionsbeiträge im Kurs Using Moodle auf moodle.org:

Vorlage:Credits [1]