One-Off Tasks in Linux: A Complete Guide to at and atdArticle · digest for October 28
Cinematic night-reportage shot of a system administrator at a Linux terminal with a one-off job scheduled via at.
Article4 sections≈ 4 min

One-Off Tasks in Linux: A Complete Guide to at and atd

Say you need to restart a heavy Nginx server at exactly 3:00 AM to apply an SSL certificate renewal during low traffic—or kick off a long database backup 45 minutes from now, right after a quarterly report export finishes.

Most sysadmins and developers reach for one of two habits, and both are messy:

  1. Run sleep 2700 && ./backup.sh & in a terminal and pray the session doesn't drop, SSH doesn't blink, and the OOM killer spares the background process.
  2. Open crontab -e, hurriedly calculate the exact minute and hour for a one-line entry, and then wonder the next morning which of five user crontabs still has that leftover junk.

Yet nearly every Linux distribution has shipped a dedicated subsystem for one-off delayed jobs for decades: the at(1) utility and its background daemon, atd.

How at Fundamentally Differs from Cron

Let's look at the architectural difference between the two schedulers.

Cron was built for recurring, periodic tasks: rotating logs every Sunday at midnight, checking disk space every 15 minutes. It knows nothing about your interactive session—commands in crontab run with a stripped-down environment, no tie to your current working directory, and often under a different shell (sh).

at, by contrast, is built strictly for one-time runs. And its killer feature is capturing a complete environment snapshot:

  • The moment you invoke at, it snapshots your current environment variables (PATH, USER, locale settings, custom exports).
  • It records the exact path of your Current Working Directory.
  • It saves your current file-creation mask (umask).

When the scheduled time arrives, atd wakes up, restores that entire environment, and runs the command in the exact context where you queued it. Your script won't mysteriously fail because a binary isn't in PATH or the working directory changed.

Human-Readable Time Syntax: From teatime to Relative Offsets

at's time parser is one of the friendliest in the UNIX world, understanding dozens of natural expressions:

# 1. Run at an exact time today (or tomorrow if that time has already passed)
at 03:00
at 11:45 PM

# 2. Relative offsets from the current time
at now + 45 minutes
at now + 3 hours
at now + 2 days

# 3. Classic English time aliases
at midnight       # Exactly 00:00
at noon           # Exactly 12:00
at teatime        # Traditional teatime (16:00)

# 4. Exact calendar dates
at 04:00 2026-11-15
at 10:00 AM tomorrow

You can pipe commands into at via standard input, pass a script file with -f, or type them interactively:

# Restart the web server at 03:00 AM using a heredoc
at 03:00 << 'EOF'
systemctl restart nginx
echo "Nginx restarted successfully" >> /var/log/maintenance.log
EOF

# Run a heavy cleanup script 45 minutes from now
at now + 45 minutes -f /opt/scripts/cleanup-cache.sh

In interactive mode, just type at 23:30, hit Enter, type as many shell commands as you need, and press Ctrl+D when you're done.

Managing Queues, Inspecting Jobs, and Removing Tasks

Queued jobs live in /var/spool/at/ or /var/spool/cron/atjobs. You manage them with atq and atrm:

# List all pending one-off jobs in the queue
atq
# Output format:
# 4    Wed Oct 28 23:30:00 2026 a romach
# 5    Thu Oct 29 03:00:00 2026 a root

# Inspect job #4 (shows the captured environment and script body)
at -c 4

# Remove job #4 from the execution queue
atrm 4

at -c <job_id> is especially handy for debugging: it prints the full generated shell script, including every exported environment variable and the exact commands queued to run.

If you'd like to compare this with recurring scheduling, check out our companion piece: a complete guide to Cron and crontab in Linux, from basic schedules to hidden environment traps.

Access Control and Managing the atd Service

For at to execute anything, the atd daemon has to be running. Check and enable it with systemctl:

# Check the daemon status
systemctl status atd

# Enable and start atd if it isn't running
sudo systemctl enable --now atd

Administrators can control who is allowed to schedule jobs using /etc/at.allow and /etc/at.deny. If /etc/at.allow exists, only users explicitly listed in it are permitted to queue tasks with at.

Reach for at whenever you have one-off maintenance to schedule—it protects your scripts from dropped SSH sessions and keeps your crontab free of temporary clutter.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 2