You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Crontab表达式解析咨询及自定义模式创建方法讲解(附示例)

Hey there! I get that crontab expressions can feel tricky when you're just starting out—let's break down the basics first, then walk through each of your given examples to make everything crystal clear.

Crontab Expression Breakdown for Beginners

First, let's recap the standard crontab structure—every cron job uses 5 mandatory fields in this fixed order:

Minute (m)  Hour (h)  Day of Month (dom)  Month (mon)  Day of Week (dow)

Each field has valid ranges you need to keep in mind:

  • Minute: 0-59
  • Hour: 0-23 (0 = midnight, 23 = 11 PM)
  • Day of Month: 1-31
  • Month: 1-12 (or shorthand like Jan, Feb if you prefer)
  • Day of Week: 0-6 (0 = Sunday on most systems; some use 7 = Sunday, so double-check your system docs if you're unsure)

Now let's unpack each of your expressions one by one:

1. 35 */8 * * *

Let's break down each field step by step:

  • Minute: 35 → Runs exactly at the 35th minute of the hour
  • Hour: */8 → Every 8 hours starting from midnight (so 0:00, 8:00, 16:00)
  • Day of Month: * → Any day of the month
  • Month: * → Any month of the year
  • Day of Week: * → Any day of the week

What it does: This job runs at 0:35, 8:35, and 16:35 every single day, no exceptions.

2. 9,35 * * * *

Field breakdown:

  • Minute: 9,35 → Runs at two specific minutes each hour: the 9th and 35th minute
  • Hour: * → Every hour of the day
  • Day of Month: * → Any day
  • Month: * → Any month
  • Day of Week: * → Any day of the week

What it does: This job triggers twice per hour, every hour, every day. So 1:09, 1:35, 2:09, 2:35, and so on around the clock.

3. 47 6 * * 7

Field breakdown:

  • Minute: 47 → Runs at the 47th minute
  • Hour: 6 → Runs at 6 AM (since hour 6 corresponds to 6 in the morning)
  • Day of Month: * → Any day of the month
  • Month: * → Any month
  • Day of Week: 7 → Runs only on Sundays (note: some systems use 0 for Sunday, but 7 is also widely accepted—test with a quick dummy job if you're unsure about your system's behavior)

What it does: This job runs every Sunday at 6:47 AM, regardless of which date that Sunday falls on.

4. 52 6 1 * *

Field breakdown:

  • Minute: 52 → Runs at the 52nd minute
  • Hour: 6 → Runs at 6 AM
  • Day of Month: 1 → Runs only on the 1st day of the month
  • Month: * → Any month
  • Day of Week: * → Any day of the week (doesn't matter if the 1st is a Monday, Friday, etc.)

What it does: This job runs on the 1st day of every month at 6:52 AM, no matter what day of the week that is.

Quick Pro Tips for New Cron Users

  • To edit your crontab, run crontab -e in your terminal (it'll open your default text editor to add/modify jobs).
  • If you want to test if an expression works as expected, set up a dummy job that writes to a log file—for example:
    35 */8 * * * echo "Job ran at $(date)" >> /home/yourusername/cron_test.log
    
  • Check cron logs to debug issues: on most Linux systems, logs are at /var/log/cron or /var/log/syslog (search for entries tagged with CRON).

内容的提问来源于stack exchange,提问作者tm_2906

火山引擎 最新活动