Difference between revisions of "Cron"
Jump to navigation
Jump to search
m |
|||
Line 25: | Line 25: | ||
* A list is defined by comma's E.g. 2,4,6 in minute -> execute command on minute 2, 4 and 6 | * A list is defined by comma's E.g. 2,4,6 in minute -> execute command on minute 2, 4 and 6 | ||
* For month and day-of-week also names can be used by giving the first 3 characters (case insensitive) | * For month and day-of-week also names can be used by giving the first 3 characters (case insensitive) | ||
+ | * For cron the week starts on Sunday so 0 is Sunday, 7 is Saturday | ||
Example: | Example: | ||
− | Every Sunday at noon execute my script:< | + | Every Sunday at noon execute my script: |
− | + | <syntaxhighlight lang=bash> | |
+ | 00 12 * * sun /usr/local/bin/myscript.sh | ||
+ | 00 12 * * 0 /usr/local/bin/myscript2.sh | ||
+ | </syntaxhighlight> | ||
;crontab -l | ;crontab -l | ||
:List the current crontab | :List the current crontab | ||
+ | |||
+ | ;crontab <crontabfile> | ||
+ | :Load the file into the crontab, all existing content will be replaced. In the end a user crontab is stored in /var/spool/cron/crontabs/<username>. Don't edit it there, the cron daemon will only read it if told so by the crontab command. | ||
+ | |||
+ | ;crontab -e | ||
+ | :Edit the current crontab directly in the default editor. Change the default editor by setting the EDITOR environment variable. |
Revision as of 12:56, 29 March 2019
Timed execution of commands. The cron daemon is checking the crontab every minute to see if anything needs to be done
- Format of crontab
minute | hour | day-of-month | month | day-of-week | command |
---|---|---|---|---|---|
1-59 | 1-23 | 1-31 | 1-12 | 0-7 | doit |
In scheduling fields (all except the command) following applies:
- * means each tick is matched.
- A range is defined by a dash. E.g. 2-5 in minute -> execute command on minute 2,3,4 and 5
- A list is defined by comma's E.g. 2,4,6 in minute -> execute command on minute 2, 4 and 6
- For month and day-of-week also names can be used by giving the first 3 characters (case insensitive)
- For cron the week starts on Sunday so 0 is Sunday, 7 is Saturday
Example: Every Sunday at noon execute my script:
00 12 * * sun /usr/local/bin/myscript.sh
00 12 * * 0 /usr/local/bin/myscript2.sh
- crontab -l
- List the current crontab
- crontab <crontabfile>
- Load the file into the crontab, all existing content will be replaced. In the end a user crontab is stored in /var/spool/cron/crontabs/<username>. Don't edit it there, the cron daemon will only read it if told so by the crontab command.
- crontab -e
- Edit the current crontab directly in the default editor. Change the default editor by setting the EDITOR environment variable.