Thursday, March 16, 2023
HomeNetworkingUtilizing the at command to schedule duties on Linux

Utilizing the at command to schedule duties on Linux


To schedule a command or script to run at some specific time, the at command is ideal and gives many choices for specifying the time you need it to run. It is going to set the duty as much as be run everytime you specify, and you may view the scheduled duties and even change your thoughts and cancel one in all them as you see match.

The at command differs from cron in that it units up a command or script to run solely as soon as, whereas cron means that you can arrange instructions or scripts to be run on a specified schedule – whether or not each day, as soon as per week, a pair occasions a month and even simply annually.

at command syntax

Utilizing the at command is comparatively simple, although it has loads of choices, significantly on the way you specify the time a process needs to be run. For those who specify a time like proven under, the duty can be set as much as be run the following time you attain 15:27 (3:27 PM), whether or not that is right now or tomorrow.

$ at 15:27
warning: instructions can be executed utilizing /bin/sh
at Wed Mar 15 15:27:00 2023
at> echo "It really works!" > /tmp/take a look at
at> <EOT>
job 5 at Wed Mar 15 15:27:00 2023

Finish the at command by urgent ^D.

Within the subsequent instance, the command is ready to run the next date on the time specified.

$ at 12:34 tomorrow
warning: instructions can be executed utilizing /bin/sh
at Wed Mar 15 12:34:00 2023
at> echo 1234 >> /tmp/wow
at> <EOT>
job 6 at Wed Mar 15 12:34:00 2023

You possibly can specify the time of day in both of two codecs. For those who ask to have a command run at 11:11, it will likely be run at 11:11 AM. To specify it to run at 11:11 PM, use 23:11 or 11:11pm because the time.

Dates could be additionally laid out in any of those codecs:

MMDD[CC]YY
MM/DD/[CC]YY
DD.MM.[CC]YY
[CC]YY-MM-DD

It’s also possible to specify a process on some specific date by specifying a weekday (e.g., Sunday).

$ at midday Wednesday
warning: instructions can be executed utilizing /bin/sh
at Wed Mar 15 12:00:00 2023
at> date >> /tmp/take a look at
at> <EOT>
job 7 at Wed Mar 15 12:00:00 2023

Itemizing at jobs

To record the duties scheduled with the at command, use the atq (at queue) command.

$ atq
5      Wed Mar 15 15:27:00 2023 a shs
6      Wed Mar 15 12:34:00 2023 a shs
7      Wed Mar 15 12:00:00 2023 a shs

The command reveals the roles ready to be run, however not the duties they are going to be operating. The small print solely embody the job numbers, the occasions they may run and the person who added them. Solely root is ready to view the entire scheduled duties. Different customers will see solely their very own.

Deleting at jobs

You possibly can cancel a scheduled job with the atrm command.

$ atrm 5
$ atq
6      Wed Mar 15 12:34:00 2023 a shs
7      Wed Mar 15 12:00:00 2023 a shs

The command under gives an inventory of instructions related to the at command.

$ sudo dnf repoquery -l at | grep bin
[sudo] password for shs:
Final metadata expiration test: 1:16:38 in the past on Fri 10 Mar 2023 01:40:19 PM EST.
/usr/bin/at
/usr/bin/atq
/usr/bin/atrm
/usr/bin/batch
/usr/sbin/atd
/usr/sbin/atrun
/usr/bin/a

Wrap-up

Commonly scheduled duties needs to be arrange utilizing the cron command, however to run some specific process at some specific time (no repeats), the at command is versatile and straightforward..

Copyright © 2023 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments