Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
In this tutorial, we'll learn about the at
command in Linux and how to use it for scheduling one-time tasks.
at
commandThe at
command in Linux allows you to schedule a task to be executed at a specific time in the future. This command is useful for running one-time tasks such as scripts, updates, or other operations that need to be executed at a specified time.
at
packageOn some Linux distributions, the at
package may not be installed by default. You can install it using the package manager:
On Ubuntu/Debian-based systems:
sudo apt-get update sudo apt-get install at
On CentOS/RHEL-based systems:
sudo yum install at
at
commandTo schedule a task with the at
command, simply type at
followed by the time when the task should be executed. The time can be specified in various formats:
Absolute time (HH:MM):
at 14:30
Relative time (e.g., "now + 1 hour"):
at now + 1 hour
Time with a date (e.g., "tomorrow 14:30"):
at tomorrow 14:30
After specifying the time, you'll be prompted to enter the commands to be executed at that time. Enter the commands, press Ctrl-D
to end the input, and the task will be scheduled.
Example:
$ at 14:30 warning: commands will be executed using /bin/sh at> echo "Hello, World!" > /tmp/hello.txt at> <EOT> job 1 at Mon Sep 20 14:30:00 2021
This example schedules a task to create a file named hello.txt
in the /tmp
directory with the contents "Hello, World!" at 14:30.
To list your scheduled tasks, use the atq
command:
atq
This will display a list of scheduled tasks with their job IDs, execution times, and queue names.
To remove a scheduled task, use the atrm
command followed by the job ID:
atrm <job-id>
Replace <job-id>
with the ID of the task you want to remove. This will delete the task from the at
queue.
To view the commands that will be executed by a scheduled task, use the at -c
command followed by the job ID:
at -c <job-id>
Replace <job-id>
with the ID of the task you want to view. This will display the commands and the environment variables set for the task.
By understanding and using the at
command in Linux, you can effectively schedule one-time tasks to be executed at specific times in the future, automating various operations and making your system more efficient.
Scheduling tasks with at
in Linux:
at
command to schedule tasks to run once.at 10:30 PM
Executing commands at a specific time in Linux:
at
.at 2:00 AM < command-to-run
Using at
command for one-time tasks in Linux:
at
command.at now + 1 hour < command-to-run
Recurring tasks with at
command in Linux:
at
command.echo "command-to-run" | at now + 1 day
Specifying date and time formats with at
in Linux:
at -m 10:30 PM
Viewing and managing scheduled jobs with atq
:
atq
to view a list of scheduled jobs.atq
Removing scheduled jobs with atrm
in Linux:
atrm
.atrm job-number
Checking at
command history in Linux:
at
command history for executed tasks.tail -f /var/log/at.log
Redirecting output and errors with at
in Linux:
at now + 1 hour < command-to-run > output.log 2>&1
Running scripts with at
command in Linux:
at
command.at now + 1 hour -f script.sh
Batch processing with at
in Linux:
at
.at now + 1 hour <<EOF command-1 command-2 EOF
Combining cron
and at
for task scheduling in Linux:
cron
for recurring tasks and at
for one-time or ad-hoc tasks.0 3 * * * /path/to/daily-script.sh