Operations 11 min read

Master Linux Task Scheduling: at, batch, crontab, and anacron Explained

This guide walks you through Linux's task‑scheduling tools—at, batch, crontab, and anacron—covering one‑time and periodic job setup, command syntax, permission files, and practical examples to automate system administration tasks.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Task Scheduling: at, batch, crontab, and anacron Explained

One‑time task commands: at and batch

The at command schedules a single execution at a specified time. Syntax: at [-v] [-q queue] [-f file] [-mldbv] TIME, where TIME can be HH:MM, MMDDYY, or expressions like now+3days. After entering the time, at enters interactive mode; finish input with Ctrl+D. Results are emailed to the invoking user.

Key options: -V: display version -q queue: select a queue (a‑z, A‑Z) -m: mail output regardless of result -f file: read commands from a file -l: list jobs (or atq) -d: delete a job (or atrm) -v: list completed but not yet removed jobs

Examples:

at 5:30pm
at 17:30
at now + 5 hours

Permissions are controlled by /etc/at.allow and /etc/at.deny. If /etc/at.allow exists, only listed users may use at; otherwise /etc/at.deny is consulted, and if both are absent, all non‑root users can run it.

The batch command works like at but runs when system load is low, without a specific time.

Periodic task commands: crontab

The crontab utility schedules recurring jobs. System‑wide jobs are defined in /etc/crontab; user jobs reside in /var/spool/cron (one file per user). Basic usage: crontab -e to edit, crontab -l to list.

Crontab file format consists of five time fields (minute, hour, day of month, month, day of week) followed by the command. Wildcards ( *) represent all values; / specifies step values (e.g., */5 every 5 units), commas separate lists, and hyphens define ranges.

Example entries: 0 8 5 6 * command – runs at 08:00 on June 5th. 10,30,50 * * * * date – shows the date at minutes 10, 30, and 50 each hour. 0 6 * * * echo "good morning" >> /tmp/test.txt – runs daily at 06:00; output is mailed to the user.

Environment variables are minimal (e.g., sh, $HOME, $MAILTO) and are defined in /etc/crontab. Output and errors are mailed to the user unless redirected.

Permission control uses /etc/cron.allow and /etc/cron.deny; presence of cron.allow overrides cron.deny.

For simpler scheduling, scripts placed in /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, or /etc/cron.monthly are executed automatically at the corresponding intervals.

Anacron: supplemental execution

anacron

runs missed periodic jobs after a reboot, using the configuration file /etc/anacrontab. It ensures tasks like log cleanup or system maintenance are not skipped if the machine was off during their scheduled time.

Understanding and correctly configuring these tools is essential for reliable automated system administration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Automationtask schedulingLinuxcronSystem Administrationat
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.