at
Schedule commands for later execution
TLDR
Create commands interactively and execute them in 5 minutes (press
Create commands interactively and execute them at a specific time
Execute a command from stdin at 10:00 AM today
Execute commands from a given file next Tuesday
List all queued jobs for the current user (same as atq)
View a specied job
SYNOPSIS
at [-q queue] [-f file] [-m] TIME
at -l [-q queue]
at -r job [job...]
at -c job [job...]
TIME can be specified in many formats, e.g., "now + 5 minutes", "10:00 PM tomorrow", "next Monday", "12/25/2024".
PARAMETERS
TIME
The time at which the job should be executed. This can be an absolute time (e.g., "10:30 AM 12/25/2024") or a relative time (e.g., "now + 2 hours").
-q queue
Specifies the queue to use for the job. Queues are single characters, 'a' through 'z'. Queue 'a' is the default. Queue 'b' is reserved for batch jobs. Jobs in queues with a lower letter run with higher priority.
-f file
Reads the job commands from the specified file instead of standard input. This is useful for scheduling existing scripts.
-m
Mails the user (or the user specified by the MAILTO environment variable) even if the job produces no output. By default, mail is sent only if the job produces standard output or standard error.
-l
Lists the jobs scheduled for the current user. This is an alias for the atq command.
-r job
Removes the specified job (identified by its job number) from the queue. This is an alias for the atrm command.
-c job
Prints the contents (commands) of the specified job to standard output. This allows viewing what a scheduled job will execute.
-V
Prints the version number of the at utilities to standard error.
DESCRIPTION
at is a command-line utility used to schedule commands or scripts to be executed only once at a specified future time. It's ideal for tasks that need to run at a particular moment but are not recurring. Unlike cron, which handles repetitive tasks, at manages single-shot jobs. When at is invoked, it reads commands from standard input or a specified file, and these commands are then stored in a queue managed by the atd daemon. The atd daemon continuously monitors this queue and executes the jobs at their designated times. The at command allows users to specify various time formats, ranging from simple hours (e.g., "now + 5 minutes") to specific dates and times (e.g., "10:00 AM tomorrow"). By default, output from the scheduled commands is mailed to the user, providing notification of job completion and any output.
CAVEATS
The atd daemon must be running on the system for at jobs to be executed.
User permissions are controlled by the /etc/at.allow and /etc/at.deny files. If /etc/at.allow exists, only users listed within it can use at. If /etc/at.allow does not exist, but /etc/at.deny does, then users listed in /etc/at.deny cannot use at. If neither file exists, generally only the root user can use at, though some distributions might default to allowing all users.
Jobs scheduled with at inherit the environment variables (like PATH, HOME, etc.) that were active when the at command was invoked, not the user's current environment at the time of execution. Jobs are typically executed with /bin/sh unless a shebang (e.g., #!/bin/bash) is specified within the job's script.
COMMON TIME FORMATS
at offers great flexibility in specifying execution times:
Absolute Time: HH:MM (e.g., "09:30", "15:00"), HH:MM AM|PM (e.g., "3 PM", "10:00 AM").
Keywords: midnight, noon, teatime (16:00).
Relative Time: now + count time-units (e.g., "now + 5 minutes", "next hour", "tomorrow", "next week", "next monday", "now + 2 days").
Date: month-name day [year] (e.g., "Dec 25", "Jan 1 2025"), MMDD[YY], MM/DD/[YY], DD.MM.[YY] (e.g., "1225", "12/25/24", "25.12.2024").
INPUTTING JOB COMMANDS
After typing at TIME and pressing Enter, at will display an at> prompt. You can then type the commands you want to execute, one per line. To signal the end of the input, press Ctrl+D on an empty line. Alternatively, you can use the -f option to specify a file containing the commands, avoiding interactive input: at -f /path/to/script.sh TIME.
JOB IDENTIFICATION
Upon successful submission, at provides a job ID (e.g., "job 1234567890.a"). This ID is crucial for managing the job later, especially when using at -c to view its contents or at -r to remove it from the queue.
HISTORY
The at command is a fundamental utility in Unix-like operating systems, providing a simple yet powerful mechanism for scheduling one-off tasks. It has been a standard component of Unix distributions for many decades, reflecting a design philosophy of creating small, focused tools. The at utilities package typically includes the atd daemon, atq (for querying jobs), and atrm (for removing jobs), forming a cohesive system for asynchronous job execution.