← กลับไปคู่มือ
30 ตัวอย่างตาราง Cron ทั่วไป: ทุก 5 นาทีถึงรายเดือน
· แท็ก: cron-examples, cron-schedule, crontab-examples, automation-schedule, linux-cron
30 ตัวอย่างตาราง Cron ทั่วไป
cron expression เป็นกระดูกสันหลังของระบบอัตโนมัติบน Linux คู่มือนี้นำเสนอ 30 ตัวอย่าง cron ที่พร้อมใช้งาน จัดตามความถี่ ครอบคลุมสถานการณ์อัตโนมัติที่พบบ่อยที่สุดสำหรับนักพัฒนาและผู้ดูแลระบบ
ทุกนาทีถึงทุกชั่วโมง
1-2. ทุกนาที / ทุก 5 นาที
* * * * * /path/to/script.sh # Runs 1,440 times per day
*/5 * * * * /path/to/script.sh # Health checks, queue processing
3-5. ทุก 10 / 15 / 30 นาที
*/10 * * * * /path/to/script.sh # Monitoring dashboards
*/15 * * * * /path/to/script.sh # Data synchronization
*/30 * * * * /path/to/script.sh # Session cleanup
6-8. ทุก 1 / 2 / 6 ชั่วโมง
0 * * * * /path/to/script.sh # Top of each hour, log rotation
0 */2 * * * /path/to/script.sh # Midnight, 2 AM, 4 AM batch jobs
0 */6 * * * /path/to/script.sh # Certificate renewal checks
ตารางรายวัน
9-13. รายวันที่เวลาเฉพาะ
0 0 * * * /path/to/script.sh # Midnight — backups, DB dumps
0 3 * * * /path/to/script.sh # 3 AM — full system backups
0 6 * * * /path/to/script.sh # 6 AM — morning reports
0 12 * * * /path/to/script.sh # Noon — midday API syncs
30 23 * * * /path/to/script.sh # 11:30 PM — end-of-day billing
14-15. หลายครั้งต่อวัน
0 6,18 * * * /path/to/script.sh # Twice daily, 6 AM and 6 PM
0 8,12,16,20 * * * /script.sh # Every 4 hours during business
ตารางรายสัปดาห์
16-18. รายสัปดาห์ในวันที่เฉพาะ
0 8 * * 1 /path/to/script.sh # Monday 8 AM — weekly reports
0 17 * * 5 /path/to/script.sh # Friday 5 PM — end-of-week backups
0 0 * * 0 /path/to/script.sh # Sunday midnight — system updates
19-21. ตารางวันทำงาน
0 9 * * 1-5 /path/to/script.sh # Weekdays 9 AM — start monitoring
30 17 * * 1-5 /path/to/script.sh # Weekdays 5:30 PM — closing reports
0 9-17 * * 1-5 /path/to/script.sh# Hourly, 9-5 weekdays
รายเดือนและตามช่วงเวลา
22-24. ตารางรายเดือน
0 0 1 * * /path/to/script.sh # 1st of month — invoices
0 8 15 * * /path/to/script.sh # 15th — mid-month reports
0 0 28,29,30,31 * * /path/to/script.sh# Last day (skips shorter months)
25-27. รายไตรมาสและรายปี
0 0 1 1,4,7,10 * /path/to/script.sh # Quarterly reviews
0 0 15 */3 * /path/to/script.sh # Every 3 months
0 0 1 1 * /path/to/script.sh # Yearly — SSL renewals
28-29. สองครั้งต่อสัปดาห์และช่วงวันทำงาน
0 8 * * 1,4 /path/to/script.sh # Monday and Thursday
*/15 9-17 * * 1-5 /path/to/script.sh # Weekdays every 15 min
30. คำสั่งที่ต่อกัน
0 6 * * * /path/to/backup.sh && /path/to/cleanup.sh
คำสั่งที่สองจะทำงานเฉพาะเมื่อคำสั่งแรกสำเร็จ
การสร้าง Crontab ของคุณ
# Minute Hour Day Month Weekday Command
*/5 * * * * /opt/scripts/health-check.sh
0 6 * * * /opt/scripts/daily-backup.sh
0 18 * * 1-5 /opt/scripts/eod-report.sh
0 0 1 * * /opt/scripts/monthly-cleanup.sh
รัน crontab -e เพื่อเพิ่มรายการ cron daemon จะโหลดตารางใหม่โดยอัตโนมัติ
ทดสอบก่อนนำไปใช้
ตรวจสอบ cron expression ใหม่ทุกครั้งด้วยเครื่องมือตรวจสอบ cron expression ดูล่วงหน้า 20 เวลาทำงานถัดไปและยืนยันว่าตารางของคุณทำงานตามที่คาดไว้