Crontab

Aus Doku-Wiki
Zur Navigation springenZur Suche springen

Crontab Referenze

Code-Beispiele

  • Jede volle und jede halbe Stunde /usr/bin/befehl starten
0,30 * * * * /my/job.sh
  • Alle 5 Minuten
*/5 * * * * /my/job.sh
  • Montag bis Freitag 9.30
30 9 * * 1-5 /my/job.sh
  • Montag bis Freitag, von 9 bis 20 Uhr alle 15 Minuten befehl starten
0,15,30,45 9-20 * * 1-5 /my/job.sh
  • Samstags und Sonntags zwischen 10 und 17 Uhr alle 2 Stunden - Befehl unter einer Benutzer-ID [joe] starten
0 10-17/2 * * 6,7 joe  /my/job.sh
The day of month & day of week are ORed, which makes cron less flexible than it could be. 
I need to run a job on the 3rd Wednesday of every month, but cron won’t let me do this. 
I figured it out in the end; run every day in the 3rd week, but then check that the day is a Wednesday. e.g.
00 02 15-21 * * if [ `date +\%u` -eq 3 ] ; then run_myjob; fi
Note that the \ is used to escape the %, otherwise cron treats it as a newline.