محلل تعبيرات Cron
حلّل تعبيرات cron إلى أوصاف مفهومة واستعرض أوقات التشغيل القادمة
تعبير cron
minute hour day(month) month day(week)
الوصف بلغة مفهومة
At 9:00 AM, Mon, Tue, Wed, Thu, Fri
تفصيل الحقول
Minute
0
0–59
Hour
9
0–23
Day (month)
*
1–31
Month
*
1–12
Day (week)
1-5
0–6
أوقات التشغيل العشرة التالية
ما هو تحليل تعبيرات Cron؟
تعبير cron عبارة عن سلسلة نصية مؤلفة من خمسة حقول مفصولة بمسافات، تُعرّف جدولاً زمنياً متكرراً. نشأ هذا التنسيق في برنامج cron الخاص بنظام Unix، الذي كتبه Ken Thompson لنظام Version 7 Unix عام 1979. يمثل كل حقل وحدة زمنية: الدقيقة، والساعة، ويوم الشهر، والشهر، ويوم الأسبوع. يعني تحليل تعبير cron تحويل هذا الترميز المضغوط إلى وصف بلغة مفهومة وقائمة بأوقات التنفيذ القادمة.
يُستخدم التنسيق القياسي ذو الخمسة حقول بواسطة crontab على Linux و macOS، ومنصات CI/CD مثل GitHub Actions و GitLab CI، ومُجدولي السحابة في AWS (EventBridge) و Google Cloud Scheduler و Azure Functions، ومكتبات جدولة المهام في جميع لغات البرمجة الرئيسية. تُوسّع بعض الأنظمة هذا التنسيق إلى ستة أو سبعة حقول بإضافة حقل للثواني أو حقل للسنة، غير أن التخطيط ذو الخمسة حقول المُعرَّف بواسطة POSIX يبقى الأساس الذي تشترك فيه جميع التطبيقات.
تحليل تعبيرات cron يدوياً أمر عُرضة للأخطاء. يُنشئ التفاعل بين الحقول جداول زمنية غير واضحة: فتعبير 0 9 1-7 * 1 لا يعني 'كل اثنين في الأسبوع الأول' بل يعني 'من اليوم الأول حتى السابع من كل شهر أو أي اثنين'. يُزيل محلل cron هذا الغموض بتوسيع كل حقل وتطبيق قواعد الدمج وإنتاج الطوابع الزمنية الفعلية لتنفيذ المهمة.
لماذا تستخدم هذا المحلل؟
قراءة تعبير cron مثل 30 */6 1,15 * * من ملف إعداد ومعرفة أوقات تنفيذه بدقة يتطلب حسابات ذهنية عبر خمسة حقول. هذا المحلل يُنجز هذا العمل فوراً.
حالات استخدام محلل Cron
مرجع صيغة تعبيرات Cron
يحتوي تعبير cron القياسي على خمسة حقول مفصولة بمسافات. يقبل كل حقل أعداداً صحيحة وأحرف بدل ونطاقات وقوائم وقيم خطوة. يوضح الجدول أدناه النطاق المسموح به والمُشغّلات لكل حقل.
| الحقل | النطاق | المُشغّلات | الوصف |
|---|---|---|---|
| Minute | 0–59 | * , - / | Minute within the hour |
| Hour | 0–23 | * , - / | Hour of the day (24-hour) |
| Day (month) | 1–31 | * , - / | Day of the month |
| Month | 1–12 | * , - / | Month of the year (or JAN–DEC) |
| Day (week) | 0–6 | * , - / | Day of the week (0 = Sunday, or SUN–SAT) |
أربعة أحرف خاصة تتحكم في كيفية مطابقة القيم داخل كل حقل:
| الحرف | الاسم | السلوك |
|---|---|---|
| * | Wildcard | Matches every possible value in the field. * in the minute field means "every minute." |
| , | List | Separates individual values. 1,15 in the day field means "the 1st and 15th." |
| - | Range | Defines an inclusive range. 1-5 in the day-of-week field means "Monday through Friday." |
| / | Step | Defines an interval. */10 in the minute field means "every 10 minutes." 5/15 means "5, 20, 35, 50." |
إليك تعبيرات cron الشائعة التي تغطي معظم احتياجات الجدولة:
| التعبير | الجدول |
|---|---|
| * * * * * | Every minute |
| 0 * * * * | Every hour (at minute 0) |
| */15 * * * * | Every 15 minutes |
| 0 9 * * * | Every day at 9:00 AM |
| 0 9 * * 1-5 | Weekdays at 9:00 AM |
| 30 2 * * 0 | Every Sunday at 2:30 AM |
| 0 0 1 * * | First day of every month at midnight |
| 0 0 * * 1 | Every Monday at midnight |
| 0 0 1 1 * | January 1st at midnight (yearly) |
| 0 */6 * * * | Every 6 hours |
| 5,35 * * * * | At minute 5 and 35 of every hour |
| 0 9-17 * * 1-5 | Every hour from 9 AM to 5 PM, weekdays |
أمثلة برمجية
كيفية تحليل تعبيرات cron وحساب أوقات التشغيل التالية في اللغات الشائعة:
import cronstrue from 'cronstrue';
// Parse cron to human-readable text
cronstrue.toString('0 9 * * 1-5');
// → "At 09:00 AM, Monday through Friday"
cronstrue.toString('*/15 * * * *');
// → "Every 15 minutes"
// Validate with cron-parser and get next run times
import { parseExpression } from 'cron-parser';
const interval = parseExpression('30 2 * * 0');
console.log(interval.next().toISOString());
// → next Sunday at 02:30 UTC
// Iterate over the next 5 runs
for (let i = 0; i < 5; i++) {
console.log(interval.next().toString());
}from crontab import CronTab
from croniter import croniter
from datetime import datetime
# Parse and describe a cron expression
cron = CronTab('0 9 * * 1-5')
print(cron.next(default_utc=True))
# → seconds until next run
# Get the next 5 run times with croniter
base = datetime.now()
cron_iter = croniter('0 9 * * 1-5', base)
for _ in range(5):
print(cron_iter.get_next(datetime))
# → next 5 weekday 09:00 timestamps
# Check if a specific time matches
print(croniter.match('*/15 * * * *', datetime(2026, 3, 25, 10, 30)))
# → True (minute 30 is divisible by 15)package main
import (
"fmt"
"time"
"github.com/robfig/cron/v3"
)
func main() {
// Parse a standard 5-field cron expression
parser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
schedule, err := parser.Parse("0 9 * * 1-5")
if err != nil {
panic(err)
}
// Calculate the next 5 run times
now := time.Now()
for i := 0; i < 5; i++ {
now = schedule.Next(now)
fmt.Println(now)
}
// → next 5 weekday 09:00 timestamps
}# List current user's cron jobs crontab -l # Edit cron jobs interactively crontab -e # Add a job: run backup.sh every day at 2:30 AM # (append to crontab via pipe) (crontab -l 2>/dev/null; echo "30 2 * * * /home/user/backup.sh") | crontab - # Check syntax with a dry-run parse (requires cronie or busybox) # The system will reject invalid expressions when saving # View cron logs on systemd-based Linux journalctl -u cron --since "1 hour ago"