Linux - Crontab
Configuration
Editor
Change default editor:
Note
To persist editor, add export VISUAL=/usr/bin/vi to ~/.bash_profile
Commands
Diaply crontab:
Delete crontab:
Edit crontab:
Display crontab of a user:
Syntax
# 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 command to be executed
See values detail:
mm: minutes (00-59).hh: hours (00-23) .jj: day of month (01-31).MMM: month (01-12or: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec).JJJ: day of week (1-7or: mon, tue, wed, thu, fri, sat, sun).user (optional): Use which execute task.task: command to execute.> log (optional): redirect to a file.
For each units, we can use the following annotation:
x-y: Unit time fromxtoy(Ex:1-6).*/x: Allxtime unit (Ex:*/6).x,y,i: Unit time (Ex:2,7).
Examples
Execute plop.sh all the days of week at 02:00:
Execute plop.sh every 2 hours:
Execute plop.sh every 1 hours and 30 minutes:
Execute plop.sh every 30 minutes: