Cron Expression Generator Guide: Five-part expression and time zone pit
Servers must run time-scripts, clear caches at 3 a.m., synchronize data at 9 a.m. a week. These programs are used for Cron Expression Write. The misspelled separator, the mix of weeks and dates, or the lack of consideration of time zones, would “run away without meeting expectations”. This Guide sets out five grammatical, special symbols, preset, time zone pits, with actionable steps and decision tables on KiloCell of pages.
The core sentence.
Five-part expression: minutes hour date month week; Preset + Description + Time Zone Three-Stamp axes.
Thousands of cells provide visual fields, nine presets and real-time natural language descriptions, primary tools:Cron Expression Generator。
Cron Syntax:
Standard Linux Cron (5 bits):
| Fields | Value range | Special Symbols | Meaning |
|---|---|---|---|
| min | 0-59 | * / - |
0-59 minutes |
| Hours | 0-23 | * / - |
0-23 hours |
| Date | 1-31 | * / - |
Days of the month |
| Month | 1-12 | * / - |
1-12 |
| Week | 0-7 | * / - |
0 = Sunday, 7 = Saturday |
6 bits Cron (seconds) have a sec field.Time zone By crontab file or cron -l It is decided that this tool description does not contain time zones (the expression is shown only on the page).
What do you do on the 1,000?
tools page:Cron Expression Generator。
Manual Fields
- Open page, find Cron Expression Area.
- Five input boxes (minutes, hours, dates, month, week) to be filled in in order
0-59、0-23、1-31、1-12、0-7。 - Pages on time: Above Expression Box Display
min hour dom mon dowDown Description Box gives a natural language interpretation (e.g. " hourly whole point"). - Points Copy Take the expression away.
- Use Clear Reset。
Preset
Page Common Presets grid, click the button, which fills the field automatically and updates the description. Example:
*♪ Every minute ♪0 9 1-5• 9 a.m.-17:00 working hours per day0 0 1♪ Every month, 1 midnight ♪
Capacity boundaries
- Yes: Five fields are manually, nine are preset, described in real time, and copied.
- None: 6-bit-second fields, time zone selection (server-end decision), complexity
?Placeholder. - No substitute: The time zone and permission to manufacture a server is required to confirm the time frame and permission.
Common error and contrast
| phenomena | Reason | Processing |
|---|---|---|
| Mission runs, not the scheduled time. | 0/7 for Sunday, 1-31 for date confusion | Unified: Date not completed *It's for Sunday. 0 |
| Description of "9 o'clock" running at 8. | Time zone is 1 hour | Timezone for server-end crontab files to be confirmed |
Preset 0 9-17 1-5 I didn't think so. |
Date field used 9-17(Illegal) |
Only legal scope, date. * |
| The mission is running for no reason. | Multiple fields / Like */2 Meaning every |
Confirm. */2 Only in this field |
| Synchronising folder | Enter value has an invalid character | Input * or 0-59 Range Numbers |
| Production runs without a log. | Permissions, curontab file error, time zone | crontab -l Validation; Change sudo crontab -e |
Wrong order
- Confirms field ranges and special symbols.
- Compared with description with expectations.
- Check server time zones against
crontab -l。 - Minimum replicable expression test.
Real work scenarios
Scenario A: Clean Cache at 3 a.m. every day
0 3 * ~ 03:00 a day for execution. The description area shows "3 a.m. every day." If the server time zone is UTC+8, the task is triggered at 033.
scene B: Synchronize data by 9 o'clock a week
0 9 1 Monday (0 = Sunday) 09:00. The blog also posts a video of the event, which is being held in the city of El Niño. Avoid 1(Date) 1(weeks)
C: Reload every 5 minutes
/5 * • Implementation per minute 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 The description area is "every 5 minutes".
Scenario D: 1 point per month
0 0 1 → 1 midnight a month. Date Field 1Month *。
E: Working hours 9 am to 17:00 am/hour
0 9-17 1-5 Monday to Friday, 09:00 to 17:00 per hour. Date used *。 If the date is also filled 9-17 It's either wrong or illegal.
Scenario F: Time zone pit
Server Timezone UTC+8,0 3 * Run at 03:00; If your local computer UTC+0, describe "3 am every day" but actually run for 15:00. Production of crontab to be confirmed date command.
Safety and operational best practices
- Minimum permission for production tasks:
crontab -lConfirmed NonerootOutside command. - Backup crontab:
crontab -l > cron.bak。 - (a) Test environment first; Do not run large file missions online.
- The description area is consistent with actual expression and is written in the manual of the transport.
- Do not place a key or sensitive path in a cron command.
- Periodic
crontab -lCheck to avoid expiration of the task. - Time zone
TZ=UTC-8 crontab -eis specified in a visible format, or in a system time zone constant.
List of practices
- Production expression is dead, not dependent on presets.
- Minimum replicable test all presets.
- Confirm Server
datecommand shows the time zone. - The mission runs and reads the log to confirm whether the trigger was triggered as expected.
- Team engagement: date field and week field respectively
*and0-7。 - Backup of the crontab file.
- Do not place the cron command in a publicly available document.
FAQ
Why did my cron run off without doing what he expected?
Confirm server time zone.crontab -l Show time zone and date The orders are identical. The description area is expressed only in an expression that does not contain a time zone.
What about date fields and week fields?
Dates (1-31) control the first days of the month and weeks (0-7) control the weeks. Both often coincide: dates * + Week 1-5 Working day.
What does the preset mean by `0 9-17* 1-5 ' ?
The implementation is carried out Monday to Friday at 09:00 to 17:00 (hours). Date used *。
Six. What about Cron?
Linux defaults 5 bits.sudo crontab -e After the last row add the second field (e. g. 0 0 0 0 0 0 )。
What's a time zone pit?
The server is different from the client time zone.0 3 * Run at UTC+8 at 0300, run at UTC+0 at 1500. Production of curtab visible designation TZ.
What about the inconsistency between the description and actual implementation?
The expression is correct and the description should be consistent. Description area is guided by tools, if with a special symbol (e.g. */2The description may be simplified to read "every 2 minutes".
Is my cron message at the online tool session?
page is calculated locally, but the actual execution of the expression depends on the server. Sensitive commands are not permanently pasted in the tool.
Time and boundary of production environment
Cron is responsible for initiating orders at a certain point in time, not for ensuring that the last mission is over. If /5 * The scripts occasionally run for more than five minutes, and the next trigger may overlap with the previous example, resulting in duplicate deductions, simultaneous writing of the same document or blasting of an external interface. For tasks with side effects, locks should be placed in the script or provided using the system flock(a) Keys, queues and tarts; The generator can only generate time expression, which cannot be resolved and controlled for you.
The transition during summer breaks also produces extraordinary results. The blogger says that the government is not going to be able to take the decision.0 2 * (a) may not be implemented; It may be performed twice at a date of one hour, depending on the action being performed by the cron. When dealing with settlement, alarm or cross-regional operations, priority is given to the time zone and calendar syntaxed dispatch platform and the environment simulation switch day is being tested. It's from the regular server. date The time zone of the output and application container may also be different, and the clock of the laptop cannot be viewed alone.
Change the command to a time stamp probe before you go online, for example. echo $(date) >> /tmp/job.log, the user, path and time zone are confirmed and replaced with a formal script. Cron's environment variables are usually smaller than interactive terminals.PATH, catalogues, supporting documents and proxy addresses may be missing; Foot should be using absolute paths and visible loads of necessary configurations. Logs contain start, end, exit code and input batches, and when they fail, set a non-zero exit code to facilitate the monitoring system alert.
If the same expression is configured both in the user crontab and in the /etc/cron.d, the task will be repeated. Check it out. crontab -l, the system catalogue and packaging configuration are searched together and copies are temporarily disabled. The generator output is only the first level of grammatical check, and a small, rolling exercise is required for real access.
Observations and rollbacks before release
Before a time job goes online, replace the official command with a journal-only probe to verify the trigger time, the user, the work directory and the environment variable. (a) The location of the probe at least at the beginning, end, exit code, input batch and generation file; The official order is returned after confirmation that the log can be collected by the surveillance system. This distinguishes between the “no trigger” “not finding the order” and the “unable to return the error after the order has been executed”.
The side effects of the mission are also designed to be sour and roll back. For example, daily settlements cannot be reticked for re-trying, clean-up scripts cannot remove the latest backup together, and dispatching notifications save business batch numbers to get heavy. Expressions are checked by the generator, indicating only five syntaxes that can be deciphered, and not that the business actions are safe. Online, use small-scale exercises to keep the previous version of the crontab and script version, and when an anomaly occurs, then the copy is disabled and the stable version is restored.
Continue reading
Checking the permissions for the use of the task is also required. Cron may run in accounts different from login users, and have different access to profile files, networks and directories. List the directories, certificates and proxy configurations required for scripts and perform an exercise using the minimum permission account number; Do not give the full permission to “run first” the mission. The container environment also requires confirmation of whether the container will be restarted, whether the time zone will inherit the host and whether the durable log will be lost after the example has been destroyed.
The check also confirms the exit code of the order. A lot of scripts printed wrong but still returned 0The monitoring system will consider failure as a success; On the contrary, the short time span of reliance on external services should not be retried indefinitely. Write the number of retests, the interval between withdrawals and the final warning conditions for each mission and document the impact of repeated implementation in the manual. This is the method for expressing "when to run" and the script and the monitor for "what to do when running fails".
Use 0 3 Go "preset, gild, gild, gild, copy" once, and use it again. 0 0 1 * Test 1 per month to cover the most common pit.