at and batch: Scheduling Something Once
cron repeats. systemd timers repeat. Neither is the right shape for “do this once, at 3am, and then never again”, and using cron for it means remembering to remove the entry.
at
# check it is even installed
command -v at || echo "not installed"
systemctl status atd
Many distributions no longer install at or enable atd by default, because systemd covers the same ground. Check before relying on it.
sudo apt install at && sudo systemctl enable --now atd
sudo dnf install at && sudo systemctl enable --now atd
# interactive, ending with Ctrl+D
at 03:00
at> /usr/local/bin/cleanup.sh
at> <Ctrl+D>
job 7 at Tue Nov 24 03:00:00 2026
# from a pipe, which is what scripts do
echo '/usr/local/bin/cleanup.sh' | at 03:00
# from a file
at 03:00 -f /usr/local/bin/cleanup.sh
The time syntax
More forgiving than cron’s, and genuinely pleasant.
at 15:30 # today, or tomorrow if that has passed
at 3pm
at midnight
at noon
at teatime # 16:00, which is a real keyword
at now + 1 hour
at now + 30 minutes
at now + 2 days
at 10:00 tomorrow
at 09:00 next Monday
at 14:00 Nov 25
at 14:00 2026-11-25
teatime is not a joke. It is in the specification.
# the queue
atq
# 7 Tue Nov 24 03:00:00 2026 a colton
# what will actually run, including the saved environment
at -c 7
# cancel
atrm 7
at -c is the command worth knowing. It prints the full script, which includes the entire captured environment and is therefore long. It is also the definitive answer to “what did I actually queue”.
The environment, which beats cron
cd /srv/data
export MY_VAR=hello
echo 'pwd; echo "$MY_VAR"' | at now + 1 minute
at captures your environment, working directory and umask at queue time and restores them at run time.
That is a real advantage over cron, which runs with a minimal environment and is the single most common source of “it works in my shell and fails in cron”, as our cron guide and shell startup files guide both cover.
It cuts both ways: an environment variable you had set for an unrelated reason comes along too.
Output goes to mail
# this output is emailed, and vanishes if mail does not work
echo 'df -h' | at now + 1 minute
# so redirect it
echo 'df -h > /tmp/disk-report.txt 2>&1' | at now + 1 minute
Redirect explicitly. at mails stdout and stderr to the queueing user, which requires a working mail path. Our server mail guide covers setting one up, and writing to a file is the safer habit either way.
batch
echo '/usr/local/bin/heavy-job.sh' | batch
Runs the job when the load average drops below a threshold, default 1.5, rather than at a time.
# what is the load now
uptime
cat /proc/loadavg
# change the threshold
sudo systemctl edit atd
# or in /etc/default/atd, varies by distribution
Useful for work that should happen eventually without competing with whatever the machine is doing. A reindex, a large compression job, a batch conversion.
Our load average guide covers what the number actually means, which matters here: load is a count of runnable and blocked tasks, so a machine doing heavy I/O has a high load while the CPU is idle, and batch will defer a CPU-bound job for no good reason.
For better control, nice and ionice let the job run now at low priority, which is frequently what people actually want.
The systemd replacement
On any systemd machine, this is the modern answer and needs nothing installed.
# run once, at a time
systemd-run --on-calendar='2026-11-24 03:00' /usr/local/bin/cleanup.sh
# relative
systemd-run --on-active=1h /usr/local/bin/cleanup.sh
systemd-run --on-active=30min /usr/local/bin/cleanup.sh
# as your user rather than system-wide
systemd-run --user --on-active=10min notify-send 'reminder' 'stand up'
# what is pending
systemctl list-timers --all
systemctl --user list-timers --all
# the transient unit it created
systemctl status run-r1a2b3c4.timer
Why this is better than at:
- Output goes to the journal rather than to mail that may not work
- Resource limits are available, per our cgroups guide
- It is already installed
- Service hardening directives apply, per our hardening guide
# with limits and a timeout
systemd-run --on-active=1h \
--property=MemoryMax=2G \
--property=CPUQuota=50% \
--property=RuntimeMaxSec=30min \
/usr/local/bin/heavy-job.sh
# read what happened
journalctl -u run-r1a2b3c4.service
journalctl -t cleanup.sh
What at still has: the environment capture, and a time syntax that accepts teatime.
Which to use
| Need | Use |
|---|---|
| Repeating schedule | systemd timer, or cron |
| Once, at a time, systemd available | systemd-run --on-calendar |
| Once, at a time, portable across Unix | at |
| When the machine is idle | batch, or nice |
| Once, needing your current environment | at |
| After a delay, in a script | sleep, if short |
For a short delay inside a running script, sleep is fine and simpler than queueing anything, per our timeout and sleep guide. The scheduling tools earn their place when the delay outlives the shell you are typing in.
Access control
# who may use at and batch
cat /etc/at.allow 2>/dev/null
cat /etc/at.deny 2>/dev/null
The rules, which match cron.allow and cron.deny:
at.allowexists: only users listed in it may useatat.allowabsent,at.denyexists: everyone except those listed- Neither exists: implementation-defined, frequently root only
# allow a specific user
echo 'deploy' | sudo tee -a /etc/at.allow
Worth checking on a shared machine. A queued at job runs as the user who queued it, with their captured environment, which makes it a persistence mechanism worth auditing:
# every queued job, for every user
sudo atq -
# and inspect anything unexpected
sudo at -c <jobnum>
# the spool, for a direct look
sudo ls -l /var/spool/cron/atjobs/ 2>/dev/null
sudo ls -l /var/spool/at/ 2>/dev/null
That check belongs alongside the crontab and timer checks in our security practices guide, since at is a scheduling mechanism people forget to look at.
A reminder worth having
# the one-liner most people want
echo 'notify-send "Reminder" "The thing"' | at now + 25 minutes
# or without at
systemd-run --user --on-active=25min notify-send 'Reminder' 'The thing'
# a function for it
remind() {
local when=$1; shift
systemd-run --user --quiet --on-active="$when" \
notify-send 'Reminder' "$*"
}
remind 25min 'stand up'
remind 2h 'check the build'
Put that in your shell config, per our startup files guide, and keep it in version control with the rest.
Frequently Asked Questions
What is the difference between at and cron?
cron runs a job repeatedly on a schedule. at runs it once at a specified time and then forgets it. Using cron for a one-off means remembering to remove the entry afterwards, which is exactly the kind of thing nobody remembers.
What does batch do differently from at?
batch queues a job to run when the system load average drops below a threshold, rather than at a particular time. It suits work that should happen eventually without competing with whatever the machine is busy doing, and the default threshold is 1.5.
Does at exist on modern systems by default?
Frequently not. Many distributions no longer install the at package or enable atd, because systemd-run with its on-calendar option covers the same ground using machinery already present. Check whether atd is running before relying on it in a script.
What environment does an at job run with?
at captures your current environment when you queue the job and restores it at run time, which is different from cron and more predictable. The working directory and umask are preserved too, so a relative path behaves as it did when you queued it.
How do I see what an at job will actually run?
Use atq to list queued jobs with their numbers, then at -c with a job number to print the full script including the saved environment. That output is long because the environment is included, and it is the definitive answer to what will execute.
Where does the output of an at job go?
It is emailed to the user who queued it, which means nothing arrives if the system cannot send mail. Redirect stdout and stderr to a file in the command itself if you want to be able to read it, which is the safer habit.