JustUtils
scheduleStandard Linux cron · 5 fields

Crontab, made understandable.

Set the time visually, see what each part means, then copy a ready-to-paste cron line. No guessing which star changes what.

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.

Deploying this schedule? Read the cron time-zone and daylight-saving guide, then confirm the daemon clock and make the job safe to retry.

คู่มือ CRONTAB GENERATOR ภาษาไทย

สร้าง Cron Expression แบบ 5 ช่อง พร้อมตรวจเวลาที่งานจะทำงานจริง

Crontab ใช้ตั้งเวลาให้ Linux เรียกคำสั่งซ้ำโดยอัตโนมัติ รูปแบบมาตรฐานมีห้าช่อง ได้แก่ นาที ชั่วโมง วันที่ เดือน และวันในสัปดาห์ เครื่องมือนี้ช่วยสร้าง expression อธิบายความหมาย และแสดงเวลาทำงานถัดไปในเขตเวลาของอุปกรณ์

โครงสร้าง Cron Expression 5 ช่อง

┌──────── นาที (0-59)
│ ┌────── ชั่วโมง (0-23)
│ │ ┌──── วันที่ของเดือน (1-31)
│ │ │ ┌── เดือน (1-12)
│ │ │ │ ┌ วันในสัปดาห์ (0-7)
* * * * *  /path/to/command

เครื่องหมาย * หมายถึงทุกค่าที่อนุญาต ใช้เครื่องหมายจุลภาคสำหรับหลายค่า ขีดกลางสำหรับช่วง และ / สำหรับช่วงห่าง เช่น */5

ตัวอย่าง Crontab ที่ใช้บ่อย

*/5 * * * *

ทุก 5 นาที

0 * * * *

ต้นชั่วโมงของทุกชั่วโมง

0 9 * * 1-5

09:00 น. วันจันทร์ถึงศุกร์

0 0 * * *

เที่ยงคืนทุกวันตามเขตเวลาของเครื่อง

เวลาอ้างอิงเขตเวลาของเครื่องที่รัน cron ไม่ใช่เขตเวลาของเบราว์เซอร์เสมอ ตรวจค่าด้วยtimedatectl หรือการตั้งค่าของ container ก่อนใช้งานใน production

ทำไมคำสั่งทำงานใน Terminal แต่ไม่ทำงานใน Cron

Cron มักมี environment และ PATH สั้นกว่า shell ที่คุณเปิดใช้งานเอง จึงควรใช้ path เต็มของโปรแกรมและสคริปต์ กำหนด working directory ภายในคำสั่ง และส่ง stdout กับ stderr ไปยัง log ที่ตรวจสอบได้

กฎวันที่ที่มักเข้าใจผิด

ใน cron แบบดั้งเดิม หากจำกัดทั้งวันที่ของเดือนและวันในสัปดาห์ งานอาจทำงานเมื่อช่องใดช่องหนึ่งตรงเงื่อนไข หากต้องการให้ตรงพร้อมกันอย่างเคร่งครัด ควรใช้ * ในหนึ่งช่องแล้วตรวจเงื่อนไขเพิ่มในสคริปต์

ตรวจสอบหลังเพิ่มงานใน Crontab

  1. เปิดตารางด้วย crontab -e แล้วบันทึกโดยไม่มีข้อความผิดพลาด
  2. ใช้ crontab -l ยืนยันว่า expression และคำสั่งถูกบันทึกครบ
  3. ตรวจ service, system log หรือไฟล์ log ของคำสั่งหลังเวลาทำงานรอบแรก
  4. ทดสอบสคริปต์ด้วย environment ที่ใกล้เคียง cron และใช้บัญชีผู้ใช้เดียวกับงานจริง