Benutzer-Werkzeuge

Webseiten-Werkzeuge


crontab

Inhaltsverzeichnis

crontab

String Bedeutung cron-Schreibweise
@reboot einmalig, beim Start
@daily einmal pro Tag 0 0 * * *
@midnight einmal pro Tag 0 0 * * *
@hourly einmal pro Stunde 0 * * * *
@weekly einmal pro Woche 0 0 * * 0
@monthly einmal im Monat 0 0 1 * *
@annually einmal im Jahr 0 0 1 1 *
@yearly einmal im Jahr 0 0 1 1 *
/etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
 
# For details see man 4 crontabs
 
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

/etc/crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#  0    1       27      Mai     Montag  root    Befehl
#minute hour    mday    month   wday    who     command
#
### um 05:00 Uhr jeden Tag
0       5       *       *       *       root /usr/sbin/ntpdate -bsuv ntp1.ptb.de
#
### alle 15 Minuten
*/15    *       *       *       *       fritz   fetchmail -f /home/fritz/.fetchmailrc
#
### jeden Montag um 03:00 Uhr
0       3       *       *       1       root [Kommando]
#
### um 02:00 Uhr am 01. Juli
0       2       1       7       *       root [Kommando]
*     *     *     *     *  Befehl der ausgeführt werden soll
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- Wochentag (0 - 7) (Sonntag ist 0 und 7; oder Namen, siehe unten)
|     |     |     +------- Monat (1 - 12)
|     |     +--------- Tag (1 - 31)
|     +----------- Stunde (0 - 23)
+------------- Minute (0 - 59; oder Namen, siehe unten)

/etc/cron.d/

Man muss nicht immer die Datei /etc/crontab bearbeiten, es geht auch eleganter, indem man für jede Aufgabe eine eigene Datei mit sprechendem Namen im Verzeichnis /etc/cron.d/ ablegt.

Die Syntax einer solchen Datei ist mit der von /etc/crontab identisch:

# echo "*/15    *       *       *       *       fritz   fetchmail -f /home/fritz/.fetchmailrc" > /etc/cron.d/Mails_abholen

Allerdings muss man hierbei auf die Verwendung von erlaubten Zeichen in den Dateinamen achten!

Ob die Dateien auch gelesen werden können, kann man mit dem folgenden Kommando testen:

# run-parts --list /etc/cron.d
/etc/cron.d/Mails_abholen

Es dürfen im Dateinamen nur Klein- und Großbuschstaben, sowie Zahlen, Unter- und Bindestrich verwendet werden! Keine Punkte oder Leerzeichen!

/home/http/wiki/data/pages/crontab.txt · Zuletzt geändert: von david