コンテンツへスキップ
uencoder

cron 式をパースする方法

cron スケジュール式を読み解き、ジョブがいつ実行されるかを確認します。

问题

cron 式があり、それが定義するスケジュールを理解する必要があります。

前提条件

  • cron フィールドの理解
  • 時間ベースのスケジューリングに関する知識

ステップ

  1. 1. Learn the five fields

    A standard cron expression has five fields: minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-6, where 0 is Sunday). Each field can be a value, range, list, step (*/5), or wildcard (*).

    入力
    30 2 * * *
    输出
    minute=30, hour=2, every day
  2. 2. Interpret the expression

    Read each field to determine the schedule. '30 2 * * *' means 2:30 AM every day. '*/15 * * * *' means every 15 minutes. '0 9 * * 1-5' means 9:00 AM Monday through Friday. Special strings like @daily provide common shortcuts.

    入力
    0 9 * * 1-5
    输出
    9:00 AM, Monday-Friday
  3. 3. Calculate the next run time

    Given the cron expression and a current time, compute the next time the job will execute. This requires evaluating all five fields together, handling month lengths, and resolving day-of-month vs day-of-week interaction (OR logic in standard cron).

    入力
    0 9 * * 1-5, from: 2023-10-14 10:00
    输出
    next: 2023-10-16 09:00 (Monday)

期待される結果

cron スケジュールの明確な理解と、次回実行時刻を計算できる力。

よくあるエラー

Day of week and day of month interaction
In standard cron, if both day-of-month and day-of-week are restricted (not *), the job runs when EITHER matches (OR logic). Some implementations use AND logic. Check your implementation.
Using 7 for Sunday
Some cron implementations accept 7 for Sunday in addition to 0. Others only accept 0. Check your implementation's convention.

トラブルシューティング指引

  • If the next run time is wrong, verify the day-of-month/day-of-week interaction logic.
  • Step values (*/N) start at the field minimum, not at 1 for all fields.

セキュリティ上の制限

  • Parsing cron expressions is a read-only analysis. No security implications.

関連ツール

参考链接