CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
  • Week 1
    • 1.Operating Systems and Linux: What the Kernel Does
    • 2.Free Software and Distributions: The Ecosystem Built by Licenses
    • 3.Installation and Booting: From the Moment You Power On
    • 4.Filesystem Structure and File Types: Everything Is a File
    • 5.Week 1 Comprehensive Review: Time to See Through the Concepts
  • Week 2
  • Week 3
  • Week 4
  • Week 5
  • Week 6
    • 1.Process Management: From PIDs to Signals and Priorities
    • 2.Daemons and the Process Life Cycle: From fork and exec to Zombies and Orphans
    • 3.System Initialization: From init and Runlevels to systemd and Targets
    • 4.Job Scheduling: From cron's 5 Fields to at and batch
    • 5.Week 6 Comprehensive Review: Tying Processes, Initialization, and Scheduling Together on One Page
  • Week 7
  • Week 8
  • Week 9
  • Week 10
  • Week 11
  • Week 12
  • Week 13
  • Week 14
MLA-C01 · AssociateMachine Learning Engineer - Associate
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← Linux Master 1/Week 6/Day 4

Based on the Linux Master 1 exam syllabus·Report an error

Linux Master 1· AssociateWeek 6 · Day 4~20 min read

Day 4 - Job Scheduling: From cron's 5 Fields to at and batch

📌 Key Takeaways

  • Scheduling tools come in two branches — recurring jobs use cron (crond), one-time jobs use at and batch (atd).
  • The crontab 5-field order is "minute (0-59) hour (0-23) day (1-31) month (1-12) weekday (0-7)". For the weekday, both 0 and 7 mean Sunday, and time is on the 24-hour clock.
  • The symbols are * (all), , (list), - (range), / (step). If you specify both day and weekday, they work as OR, not AND.
  • A user crontab has 5 fields, while a system crontab (/etc/crontab, /etc/cron.d/) has 6 fields with a user field added.
  • Access control is allow > deny — if cron.allow exists, only that list is allowed and cron.deny is ignored.

cron's Structure — The crond Daemon and crontab

  • cron is a system for scheduling recurring jobs.
  • The background daemon crond wakes up every minute, checks every user's schedule list, and runs the jobs whose time has come.
  • The file/table holding the schedule list is called the crontab (cron table).
  • The command that manages per-user crontabs is crontab.
CommandAction
crontab -eEdit my crontab (created if it doesn't exist)
crontab -lPrint my crontab list
crontab -rDelete my entire crontab
crontab -u user -eEdit a specific user's crontab (root)
crontab -e              # add/modify my scheduled jobs in an editor
crontab -l              # view the currently registered scheduled jobs
crontab -r              # delete all scheduled jobs (careful!)
crontab -u alice -l     # view alice's scheduled jobs (root privilege)

⚠️ Trap: crontab -r deletes everything without confirmation. If you mistakenly hit -r, one key away from the -e you meant to press, all your schedules vanish. In practice, the habit of backing up first with crontab -l > backup.txt is recommended. You must clearly distinguish -l (list), -e (edit), and -r (delete).

The crontab's 5 Fields — The Heart of Time Notation

  • One crontab line = 5 time fields + the command to run. The order and ranges of these 5 fields are the absolute core of the exam.
┌───────────── minute  (0-59)
│ ┌─────────── hour    (0-23)
│ │ ┌───────── day     (1-31)
│ │ │ ┌─────── month   (1-12)
│ │ │ │ ┌───── weekday (0-7, both 0 and 7 are Sunday)
│ │ │ │ │
* * * * *  command_to_run
PositionFieldRangeNotes
1minute0-59
2hour0-2324-hour clock
3day of month1-31
4month1-12jan-dec also allowed
5day of week0-70 and 7 = Sunday, 1=Mon … 6=Sat
  • Special characters express patterns.
SymbolMeaningExample
*Every value* * * * * = every minute
,List0,30 = minutes 0 and 30
-Range1-5 = 1 to 5
/Step (interval)*/10 = every 10
  • Get used to the patterns through real-world examples.
# min hour day month weekday  command
  0  3  *  *  *    /backup.sh        # every day at 3:00 a.m.
  30 2  *  *  1    /weekly.sh        # every Monday at 2:30 a.m.
  0  */6 * *  *    /check.sh         # every 6 hours (at 0, 6, 12, 18)
  */10 * * *  *    /poll.sh          # every 10 minutes
  0  0  1  *  *    /monthly.sh       # midnight on the 1st of every month
  0  9  *  *  1-5  /workday.sh       # 9:00 a.m. on weekdays (Mon-Fri)
  15 14 1  *  *    /report.sh        # 14:15 on the 1st of every month

The order of the 5 fields is "minute-hour-day-month-weekday", from the smaller time unit to the larger (the weekday alone is the exception, placed last). The weekday starts with 0=Sunday and goes to 6=Saturday, and 7 is also accepted as Sunday. Since it is the 24-hour clock, 2 p.m. is 14. Memorize this order with the mnemonic "min-hour-day-month-weekday".

⚠️ Trap: If you specify both the day (3rd) and the weekday (5th), they work as OR — the job runs if either one matches. For example, 0 0 13 * 5 runs "on the 13th of every month or every Friday" (not only on a Friday that is also the 13th), and it is not AND. This OR behavior easily becomes a trap.

Try it yourself: Use crontab -e to put in the single line */2 * * * * date >> ~/crontest.log and save. The current time accumulates in the file every 2 minutes. After a few minutes, check the accumulation with cat ~/crontest.log, and when you're done, delete that line in crontab -e. You get to see how the 5 fields actually run.

System crontab — /etc/crontab and cron.d

  • Separately from user crontabs (crontab -e), there are places for system-wide schedules — the /etc/crontab file and the /etc/cron.d/ directory.
  • The decisive difference is that there is one more user field.
  • The reason: a user crontab runs with the registrant's privileges, but a system crontab must specify which user's privileges to run with.
# /etc/crontab format (6 fields = 5 time fields + user + command)
# min hour day month weekday  user  command
  0  4  *  *  *    root    /usr/local/bin/cleanup.sh
ItemUser crontabSystem crontab (/etc/crontab)
How to createcrontab -eEdit the file directly
Number of fields5 fields + command5 fields + user + command
Run privilegeThe user who registered itThe specified user field
Storage location/var/spool/cron/username/etc/crontab, /etc/cron.d/*
  • There are also fixed per-interval directories. You don't write a time; just put a script in and it runs automatically.
DirectoryRun interval
/etc/cron.hourly/Every hour
/etc/cron.daily/Every day
/etc/cron.weekly/Every week
/etc/cron.monthly/Every month

The difference that a user crontab has 5 fields and a system crontab (/etc/crontab, cron.d) has 6 fields (user added) is a key exam point. /etc/cron.d/ is a good place for packages to add their own schedules, and it uses the same 6-field format as /etc/crontab. Directories like cron.daily take scripts without a time (the run time is managed by anacron/the system).

The word cron comes from the Greek 'chronos' (time). It has existed since 1970s Unix, and anacron was added for systems that aren't always on, like laptops — cron skips a job if the machine is off at that exact time, but anacron runs it "even right after power-on if N days have passed since the last run". This is why cron.daily and the like are tied to anacron.

Access Control — cron.allow and cron.deny

  • Who can use cron is controlled by two files.
FileMeaning
/etc/cron.allowOnly the users listed here can use cron (whitelist)
/etc/cron.denyOnly the users listed here cannot use cron (blacklist)
  • Decision rules:
    • If cron.allow exists, only that list is allowed and cron.deny is ignored.
    • If cron.allow does not exist and only cron.deny does, everyone except the deny list is allowed.
    • If neither exists, usually only root (or everyone, depending on the distribution) is allowed.

The priority is allow > deny. The moment an allow file exists it becomes the only criterion and deny loses effect. at is controlled in the same way by /etc/at.allow and /etc/at.deny.

Run Just Once — at and batch

  • If cron is "recurring", at is "exactly once". It runs a command once at the specified time and then disappears from the queue.
at 17:00                  # input mode for a command to run at 5 p.m.
at> /usr/local/bin/report.sh
at> <end input with Ctrl+D>
 
at now + 2 hours          # 2 hours from now
at 10:30 tomorrow         # 10:30 a.m. tomorrow
at midnight               # midnight today
echo "/backup.sh" | at 3am  # pass the command via a pipe
  • There are separate commands for managing at jobs.
CommandAction
at timeRegister a job to run at that time
atq (or at -l)List of pending at jobs
atrm number (or at -d)Delete a pending job
  • batch is a variant of at. It doesn't specify a time and runs automatically when the system load (load average) drops (usually below 0.8).
  • Purpose: when you want to run heavy jobs while the CPU is idle.
batch                     # runs when the system becomes idle
at> /heavy-compute.sh
at> <Ctrl+D>
Categorycronatbatch
Run countRecurringOnceOnce
When it runsFixed intervalSpecified timeWhen load is low
Daemoncrondatdatd
Registrationcrontab -eat timebatch

cron is recurring, at/batch are one-time. "Back up every day at dawn" is cron, "one-time inspection tomorrow" is at. at ends its input with Ctrl+D (EOF), the list of registered jobs is atq, and deletion is atrm (at -l/at -d work the same). The difference from at is that batch runs based on load rather than time.

Try it yourself: Run echo "echo hello > ~/at-test.txt" | at now + 1 minute and check the pending list with atq. If cat ~/at-test.txt shows hello a minute later, it worked, and the job disappears from atq (confirming it is one-time). To cancel, look up the number with atq and run atrm number.

📖 Glossary

  • crond : The daemon that wakes up every minute, inspects the schedule list, and runs jobs whose time has come.
  • crontab : The table holding the schedule list. Handled with -e (edit), -l (list), -r (delete all, no confirmation).
  • 5 fields : Time notation in the order minute-hour-day-month-weekday. Memorize it as "min-hour-day-month-weekday".
  • step (/) : The interval symbol. */10 means "every 10".
  • Day/weekday OR rule : If you fill in both the 3rd (day) and 5th (weekday), the job runs if either one matches.
  • System crontab : /etc/crontab and /etc/cron.d/*. An execution user field follows the 5 time fields, making 6 fields.
  • /etc/cron.daily/ etc. : Directories where, if you just put a script with no time, it runs at that interval.
  • anacron : For systems that aren't always on. It runs jobs cron skipped "even right after power-on".
  • cron.allow / cron.deny : Usage-permission whitelist / prohibition blacklist. If allow exists, deny is ignored.
  • at : A one-time schedule that runs exactly once at the specified time and then disappears from the queue. List with atq, delete with atrm.
  • batch : A variant of at that runs once when the system load drops, not at a given time.
  • atd : The daemon that handles at and batch jobs. It is separate from crond.

📝 Practice Questions

Click a choice to reveal the answer and explanation.

Question 1

Which of the following lists the 5 time fields of a crontab correctly from left to right?

Question 2

When does the crontab entry 30 2 * * 1 /backup.sh run?

Question 3

Which values in the crontab weekday field both represent Sunday?

Question 4

What is the run interval of a job scheduled with */15 * * * *?

Question 5

What is the biggest format difference between a user crontab (crontab -e) and a system crontab (/etc/crontab)?

Question 6

Which of the following is correct about the priority of the cron access control files /etc/cron.allow and /etc/cron.deny?

Question 7

Which of the following is correct about the differences between cron, at, and batch?

PreviousSystem Initialization: From init and Runlevels to systemd and TargetsWeek 6 · Day 3Next Week 6 Comprehensive Review: Tying Processes, Initialization, and Scheduling Together on One PageWeek 6 · Day 5

Official references

  • Linux Master 1 official exam syllabus(opens in a new tab)

On this page

  • Key Takeaways
  • cron's Structure — The crond Daemon and crontab
  • The crontab's 5 Fields — The Heart of Time Notation
  • System crontab — /etc/crontab and cron.d
  • Access Control — cron.allow and cron.deny
  • Run Just Once — at and batch
  • Glossary
  • Practice Questions