Open In App

at Command in Linux with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

In the world of Linux operating systems, there exists a powerful tool known as the “AT command.” The AT command provides users with the ability to schedule tasks to be executed at a later time, offering a convenient way to automate processes without manual intervention. Whether you need to run a script, execute a command, or perform a system task at a specific time, the AT command provides the flexibility to accomplish these tasks efficiently. In this article, we will delve into the details of the AT command in Linux, exploring its syntax, options, and practical examples.

Introduction to the AT Command:

The AT command allows users to schedule one-time tasks or recurring jobs at a specific time and date. It is particularly useful for automating system maintenance, backups, software updates, and various administrative tasks. The AT command works by queuing commands to be executed by the system’s job scheduler at the specified time.

Syntax of the AT Command:

The basic syntax of the AT command is straightforward:

at [-V] [-q queue] [-f file] [-mldbv] timespec
  • -V: Display version information.
  • -q queue: Specify the job queue. The default queue is ‘a’.
  • -f file: Read commands from the specified file.
  • -m: Send mail to the user when the job has completed.
  • -l: List the at jobs in the queue.
  • -d: Delete the at job specified by the job number.
  • -b: Submit a batch job. This is the default behavior.
  • -v: Display verbose information about the job.
  • timespec: Specify the time and date when the job should be executed.

Installation of at command

For Ubuntu/Debian :

sudo apt-get update
sudo apt-get install at

For CentOS/Fedora :

sudo yum install at

Examples of Using the AT Command:

Listing Scheduled Jobs:

To list all scheduled jobs in the AT queue, you can use the `-l` option:

at -l

or

atq

list_pending_jobs_at_command

This command will display a list of all pending jobs along with their job numbers.

Deleting a Scheduled Job:

If you need to remove a scheduled job from the queue, you can do so by specifying its job number with the -d option:

at -d 1

This command will delete the job with job number 1 from the AT queue.

Scheduling a Job for the Coming Monday

To schedule a job for the coming Monday at a time twenty minutes later than the current time, the syntax would be:

at Monday +20 minutes

This command instructs the system to execute the specified job on the upcoming Monday, twenty minutes after the current time.

Scheduling a Job for a Specific Date and Time

To schedule a job to run at 1:45 on August 12, 2020, the command is:

at 1:45 081220

Here, the command specifies the exact date and time when the job should be executed, in the format of hour:minute monthdate.

Scheduling a Job for a Future Time

If you need to schedule a job to run at 3 PM four days from the current time, the command would be:

at 3pm + 4 days

This command schedules the job to be executed at 3 PM, four days from the current time.

Scheduling a System Shutdown

To schedule a job to shutdown the system at 4:30 PM today, you can use the following command:

echo "shutdown -h now" | at -m 4:30

This command pipes the shutdown command to the AT command, specifying that the system should be shut down at 4:30 PM, and the user should receive an email notification when the job is completed.

Scheduling a Job for a Future Time Relative to Now

To schedule a job to run five hours from the current time, the command would be:

at now +5 hours
scheduling a job using at command

scheduling a job using at command

This command schedules the job to be executed five hours from the current time.

Different Method to delete job

at -r or atrm command is used to deletes job , here used to deletes job 11 .

 at -r 11

or

atrm 11
deleting a job using at command

deleting a job using at command

Conclusion:

The AT command in Linux offers a convenient way to schedule tasks for execution at a later time. By understanding its syntax and options, users can automate various system tasks and streamline their workflow effectively. Whether it’s a one-time task or a recurring job, the AT command provides the flexibility and reliability needed to manage scheduled tasks efficiently in Linux environments. By incorporating the AT command into your system administration toolkit, you can enhance productivity and ensure timely execution of critical tasks.


Last Updated : 21 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads