【the waiter】announcement:
Generate crontab expression
| | |
Guide to using Crontab
crontab
is a tool for scheduling tasks in Unix and Unix-like systems. By writing cron expressions, you can perform tasks on a regular basis.
basic syntax
* * * * * command_to_execute
- - - - -
| | | | |
| | | | └ -- What day of the week (0-7) (Sunday = 0 or 7)
| | | └ -- Month (1-12)
| | └ -- -- Date (1-31)
| └ -- -- hour (0-23)
└ -- -- Minutes (0-59)
1 time field description:
*
: matches any value.Numer
: specify a specific time.,
: indicates multiple time values. For example, 1, 3, 5 means the 1st, 3rd, 5th minute.-
: indicates the range, for example, 1-5 means from the 1st minute to the 5th minute./
: indicates the step size. For example, * / 2 means that it is executed every 2 minutes.
example
# perform a task every 5 minutes
* / 5 * / path/to/command
# perform the task at 8: 00 a.m. every Monday
0 8 * * 1 / path/to/command
# perform tasks at 2: 00 p.m. on the 1st and 15th of each month
0 14 1,15 * * /path/to/command
# perform tasks every hour from 9: 00 a.m. to 5: 00 p.m. Every working day
0 9-17 * 1-5 / path/to/command
2. Special time string
Special string | equivalent expression | description |
---|---|---|
@reboot | NumberA | execute when the system starts |
@yearly | 0 0 1 1 * | execute once a year (January 1) |
@monthly | 0 0 1 * * | execute once a month |
@roomly | 0 0 * * 0 | execute once a week |
@daily | 0 0 * * * | execute once a day |
@hourly | 0 * * * * | execute every hour |