Working with the at command to agenda duties on Linux
[ad_1]
To schedule a command or script to run at some unique time, the at command is excellent and provides lots of alternatives for specifying the time you want it to operate. It will established the process up to be run when you specify, and you can check out the scheduled responsibilities or even adjust your mind and cancel one particular of them as you see in shape.
The at command differs from cron in that it sets up a command or script to operate only as soon as, though cron makes it possible for you to set up commands or scripts to be operate on a specified schedule – whether just about every day, as soon as a 7 days, a few instances a month or even just after a year.
at command syntax
Utilizing the at command is rather simple, nevertheless it has a lot of alternatives, notably on how you specify the time a endeavor need to be operate. If you specify a time like shown underneath, the endeavor will be established up to be operate the up coming time you achieve 15:27 (3:27 PM), no matter if that is right now or tomorrow.
$ at 15:27 warning: instructions will be executed applying /bin/sh at Wed Mar 15 15:27:00 2023 at> echo "It is effective!" > /tmp/examination at>work 5 at Wed Mar 15 15:27:00 2023
End the at command by urgent ^D.
In the following case in point, the command is set to run the pursuing day at the time specified.
$ at 12:34 tomorrow warning: commands will be executed making use of /bin/sh at Wed Mar 15 12:34:00 2023 at> echo 1234 >> /tmp/wow at>task 6 at Wed Mar 15 12:34:00 2023
You can specify the time of day in either of two formats. If you request to have a command operate at 11:11, it will be run at 11:11 AM. To specify it to run at 11:11 PM, use 23:11 or 11:11pm as the time.
Dates can be also specified in any of these formats:
MMDD[CC]YY MM/DD/[CC]YY DD.MM.[CC]YY [CC]YY-MM-DD
You can also specify a undertaking on some certain day by specifying a weekday (e.g., Sunday).
$ at noon Wednesday warning: commands will be executed utilizing /bin/sh at Wed Mar 15 12:00:00 2023 at> day >> /tmp/exam at>work 7 at Wed Mar 15 12:00:00 2023
Listing at jobs
To list the tasks 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 demonstrates the careers waiting to be run, but not the jobs they will be operating. The specifics only include the task figures, the occasions they will run and the person who added them. Only root is able to see all of the scheduled duties. Other consumers will see only their very own.
Deleting at work
You 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 underneath provides a list of instructions associated with the at command.
$ sudo dnf repoquery -l at | grep bin [sudo] password for shs: Last metadata expiration check: 1:16:38 ago 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
Frequently scheduled duties should really be set up employing the cron command, but to run some particular job at some unique time (no repeats), the at command is adaptable and straightforward..
Copyright © 2023 IDG Communications, Inc.
[ad_2]
Source url