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 execute commands remotely using SSH in Linux?
Many times users need to work in remote systems. For which they have to log in to the remote server, execute certain commands and come out of that session. Is it possible to perform all these actions locally? Yes, it's possible using ssh client. In this article, we will see different ways of running
2 min read
How to List Running Processes in Linux | ps Command
As we all know Linux is a multitasking and multi-user system. So, it allows multiple processes to operate simultaneously without interfering with each other. Process is one of the important fundamental concepts of the Linux OS. A process is an executing instance of a program that carries out differe
9 min read
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 Create Time-Table Schedule using HTML?
A time table or schedule is essential for organizing tasks, events, or classes. Weâll create a basic time-table layout using HTML. A Table is an arrangement of rows and columns. Anyone can create a table by knowing the basics of HTML(HyperText Markup Language). In HTML we can use the <table> t
3 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
Task Scheduler Using HTML, CSS and JS
In this article, we will create a Task Scheduler web application using HTML, CSS and JavaScript. This is an application which can store tasks provided by user and classified them as low priority, middle priority, and high priority. User also can provide a deadline for the task. User also can mark do
3 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
6 min read
Shell Script to Demonstrate Wait Command in Linux
Wait command is one of the process management commands. There are different process commands in Linux mainly 5 commands are widely used which are ps, wait, sleep, kill, exit. ps is an acronym for process status. It displays information about the active processes. wait command will suspend execution
4 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 AccountPos
2 min read