How to Schedule Tasks Using at Command in Linux
Last Updated :
11 Mar, 2024
The at command in Linux is used to schedule one-time tasks to be executed at a specified time in the future. It allows users to submit a command or script for execution at a later time, offering a convenient way to automate tasks without the need for complex cron jobs. The scheduled jobs are managed by the atd (at daemon) service, which runs in the background and executes the queued tasks at the specified times. In this article, we will explore the at command and the atd service used by the at command in Linux.
at command in Linux
The at command in Linux is used for scheduling one-time tasks to be executed at a specified time. Users can submit commands or scripts, and the atd daemon manages the execution of these scheduled jobs. It provides a simple way to automate future tasks without the need for complex cron expressions.
Syntax:
The basic syntax of the at command is as follows:
at [-q queue] [-f file] [-mldv] TIME
-q queue
: Specifies the job queue (default is "a").-f file
: Reads the job from the specified file.-m
: Sends an email to the user after the job has been executed.-l
: Lists the user's pending jobs.-d
: Deletes a pending job.-v
: Displays the time of job execution.
How to Schedule Tasks Using at Command in Linux
Example 1: Scheduling a command to run at a specific time:
at 2:30 PM
at> echo "Hello, World!" > ~/hello.txt
at> Ctrl+D
This example schedules the echo command to write "Hello, World!" to a file at 2:30 PM.

Example 2: Using a file to specify commands:
$ echo "ls -l" > myscript
$ at 10:00 PM -f myscript
In this example, a script file (myscript) containing the ls -l command is scheduled to run at 10:00 PM.

Example 3:System Shutdown at Specific Date:
at 11:45pm July 31
at> shutdown now
In this example , the computer will shutdown on a specific date

Example 4 : Delete a file on a specific Time:
at 11:45pm
at> rm hello.txt
In this example the hello.txt file will be removed at 11:45PM today

Which service is used by at command in Linux?
The at command in Linux is used to schedule one-time tasks to be executed at a specified time in the future. It utilizes the atd (at daemon) service, which runs in the background and manages the execution of these scheduled jobs. Users can use the at command to submit commands or scripts along with the desired execution time, and atd ensures their execution at the specified time.
How atd service manages at command in Linux?
The atd (at daemon) in Linux manages the execution of commands scheduled using the at command. When a user submits a job using the at command, the job details are stored in the /var/spool/at directory. atd periodically checks this directory for pending jobs and, when the scheduled time arrives, it executes the jobs on behalf of the user. atd ensures the proper handling of scheduled tasks, managing their execution without requiring continuous user involvement, making it an efficient solution for one-time job scheduling in Linux systems.
Components of atd service:
- Job Queue: The
atd
service maintains a queue of jobs scheduled to run at specific times. Each job is associated with a particular time of execution. - Scheduler: The scheduler component
atd
checks the scheduled jobs in the queue and ensures that tasks are executed at the specified times. - Executor: When the scheduled time arrives, the executor component
atd
is responsible for launching and executing the specified commands or scripts associated with each job. - Time Handling: The
atd
service manages the timing aspects of job execution. It calculates the time differences between the current time and the scheduled execution time to ensure accurate job execution. - Logging and Reporting:
atd
may include components for logging and reporting. It logs information about job submissions, executions, and errors. Users can often check the status and history of their scheduled jobs.
Conclusion
In conclusion, the at command in Linux provides a solution for scheduling one-time tasks efficiently, using the atd service for job management. Users can easily automate future tasks without the complexity of cron jobs. Understanding the syntax and examples helps the scheduling process, while monitoring and troubleshooting can be performed through commands like systemctl status atd.
Similar Reads
How to Automate Tasks with Cron Jobs in Linux? Tired of repeating the same tasks every day? Feeling like your computer's to-do list is multiplying faster than dust bunnies? Well, say goodbye to manual madness and hello to cron jobs! Think of them as your robot assistants in the land of Linux, diligently taking care of those repetitive chores whi
9 min read
How to Build Your Own Commands in Linux? Linux is one of the most widely used open-source operating systems which supports both GUI as well as CLI. It has been widely used all over the world since its first distribution launched on September 17, 1991, by Linus Torvalds. It is widely known for its command-line operations. We have been using
6 min read
Process Control Commands in Unix/Linux Process control commands in Unix are: bg - put suspended process into background fg - bring process into foreground jobs - list processes bg Command : bg is a process control command that resumes suspended process while keeping them running in the background. User can run a job in the background by
3 min read
How to Schedule an Email in Gmail In today's digital age, email is an indispensable tool for both personal and professional communication. While we often send emails immediately, there are times when scheduling an email to be sent later is more beneficial. Scheduling emails in Gmail ensures timely delivery, even when you're unavaila
7 min read
How to Manage System Services in Linux | systemctl Command Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool
8 min read
How to use Postman Monitors to schedule and run collections? Postman is a popular API development tool that offers a powerful " Monitors " feature that allows you to automate the execution of collections at scheduled intervals. This article will explore the step-by-step instructions for using Postman Monitors.Prerequisites:Postman InstalledPostman AccountPost
2 min read