Cron Reference: पाँच fields, खास characters और gotchas
Cron commands को पाँच fields — minute, hour, day of month, month और day of week — में बताए schedule पर चलाता है, जिनके बाद खुद command आता है। 30 9 * * 1 जैसी एक line का मतलब है हर Monday सुबह साढ़े नौ, और लगभग हर Unix system समेत अनगिनत schedulers यही बोली बोलते हैं।
1. Fields और allowed values
Minutes 0 से 59, hours 0 से 23, days of month 1 से 31, months 1 से 12 और weekdays 0 से 7 तक होते हैं, जहाँ 0 और 7 दोनों Sunday हैं। Star का मतलब उस position में हर value है, इसलिए 0 * * * * हर hour की शुरुआत में fire होता है।
2. Steps, ranges और lists
Slash step तय करता है — minute field में */15 का मतलब हर पंद्रह minute — hyphen range तय करता है जैसे Monday से Friday के लिए weekday 1-5, और commas 0,30 जैसी lists जोड़ते हैं। ये खुलकर compose होते हैं, इसलिए 0 9-17 * * 1-5 का मतलब है working day में हर hour एक बार, सिर्फ weekdays पर।
3. Day-fields वाली OR quirk
जब day-of-month और day-of-week दोनों fields restricted हों, तो cron either match होने पर fire होता है — दोनों पर नहीं। महीने के पहले Monday वाली line को extra care चाहिए, क्योंकि दोनों fields restrict करने से schedule सँकरा होने के बजाय चौड़ा होता है। दोनों में से एक को star छोड़ देने से दूसरा पूरी तरह प्रभारी रहता है।
4. Presets और environment के जाल
Daily या weekly जैसे shorthands field patterns में expand होते हैं, लेकिन classic पाँच-field form systems के बीच सबसे अच्छा चलता है। याद रखें कि cron minimal environment में चलता है: आपके terminal के paths, locales और shell quirks साथ नहीं आते, इसलिए हमेशा absolute paths इस्तेमाल करें और command को पहले हाथ से test करें। Expressions को visually बनाएँ और अगले runs का preview हमारे cron generator से करें, जो upcoming dates आपके browser में ही compute करता है।