JustUtils
scheduleStandard Linux cron · 5 fields

งาน Cron วันธรรมดา เวลา 9 นาฬิกา

สร้างงาน Cron วันจันทร์ถึงศุกร์เวลา 9 นาฬิกาด้วย 0 9 * * 1-5 เพิ่มคำสั่งแล้วคัดลอกบรรทัด crontab

Your schedule

Edit the expression directly, or adjust one field at a time.

lightbulb

In plain English

At 09:00, Monday through Friday.

Next 5 execution times

Calculating upcoming times…

Start with a common schedule

Choose one to replace the expression above. Then fine-tune it.

Ready-to-paste cron line

Add the command that should run with this schedule.

terminal
0 9 * * 1-5 /usr/local/bin/backup.sh

Tip: use full paths for scripts and commands. Cron has a smaller environment than your terminal.

warningOne important cron rule

When both “day of month” and “day of week” are restricted, traditional cron may run when either one matches. If you need a precise combination, use * in one of those fields or put the extra condition in your script.

THE SIMPLE VERSION

What is crontab?

Crontab is your computer's quiet to-do list for repeat work. You write a time pattern and a command; Linux checks the list each minute and starts the command whenever the pattern matches.

It is useful for jobs you do not want to remember: backups, report emails, cleanup tasks, or syncing data. The schedule says when; the command says what.

Using it on Ubuntu

Open your personal schedule

crontab -e

Choose an editor the first time. Paste a cron line, save, and exit.

List saved jobs

crontab -l

Shows the schedules currently installed for your user.

Remove all your jobs

crontab -r

This deletes your personal crontab immediately—use with care.

คำอธิบายตัวอย่าง CRONTAB

ตรวจตาราง weekdays at 9 am กับเขตเวลาและ environment ของเครื่องจริง

ตัวอย่างช่วยเติม Cron Expression ได้รวดเร็ว แต่เวลาที่งานทำงานอ้างอิงเครื่องหรือ container ที่ติดตั้ง crontab ไม่ใช่เวลาของเบราว์เซอร์เสมอ และคำสั่งยังอาจมี PATH ต่างจาก Terminal ที่ใช้งานปกติ

ก่อนบันทึกตัวอย่างนี้

  • อ่านคำอธิบายของทั้งห้าช่องและตรวจเวลาทำงานถัดไปหลายรอบ
  • ยืนยันเขตเวลาด้วยการตั้งค่าของระบบปลายทาง โดยคำนึงถึง daylight saving time หากเกี่ยวข้อง
  • ใช้ path เต็มของโปรแกรม กำหนด working directory และส่ง error ไปยัง log
  • ตรวจรอบแรกจาก system log หรือ output ของงานก่อนถือว่าการตั้งค่าสำเร็จ

ข้อจำกัดของ Cron Expression

Cron แบบมาตรฐานไม่มีวินาทีและไม่รับประกันว่างานรอบก่อนจบก่อนรอบใหม่เริ่ม หากงานใช้เวลานานควรเพิ่ม lock หรือระบบ queue

การพลาดรอบขณะเครื่องปิดมักไม่ถูกทำย้อนหลังโดย cron ปกติ งานที่ต้อง catch up อาจเหมาะกับ systemd timer หรือ scheduler ของระบบมากกว่า