Using at command in Linux


Gaming Laptop Series

The at is a command-line utility that is used to schedule a task to run automatically at a particular time in the future. For example, you can schedule a mail program to send mail automatically at a given time.

at is most suitable for scheduling one-time tasks for repetitive tasks such as taking backup every week on a particular day cron is used. Now In this article, you will learn the usage of at command in Linux with some examples.

How to install at command on Linux

Some distribution may have at command preinstalled if it is not present on your system then use one of the given commands to install it.

To install at on Debian/Ubuntu/Linux Mint, use –

sudo apt install at

If you are using Centos/RHEL then use –

sudo yum install at

In Fedora execute the given command –

sudo dnf install at

After executing this command if it asks for your confirmation press y and then enter.

Enable the job scheduling daemon

The atd is the scheduling daemon make sure it is enabled so that when you restart your system the at services get automatically started. Use the following command to start and enable it at boot time –

systemctl start atd
systemctl enable atd

You can check its status by using –

systemctl status atd

How to use at command in Linux

The syntax of using at command on a Linux system is given below-

at [option..] runtime

You can find the option that can be used with the at command on its man page. And the runtime is the time when you want to execute the job.

Steps to schedule a job with at command

Follow the given steps to schedule a job using the at command in Linux.

Step1: Start the at utility by specifying the time and date you want your job executed.

Step2: Enter the command or script on the at prompt one per line

step3: When you are done entering the command press Ctrl+D to save the job.

Examples of scheduling jobs using at command

To schedule a job for coming Sunday 30 minutes later than the current time then you need to use the following command.

at Sunday +30 Minutes

For example –

The system will run for update and upgrade commands on Sunday 30 minutes after the current time.

To schedule, a job for a specific date let’s say 10 May 2021 at 12 PM then you need to use the following command –

at 12:00 051021

To check the jobs in queue use the following command –

atq

This will display all the jobs scheduled on your system. You can see this in the image below –

To remove a job from the queue use atrm command –

atrm 6

This command will remove job 6 from the queue.

Now to know more about at command use the following command in your terminal.

man at

Conclusion

Use corn if you want to schedule the repetitive job, if you want to execute the job once then use at command. Now if you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.