at

Execute a task at a specified time

Supplementary instructions

at command is used to execute commands at a specified time. at allows a rather complex set of methods for specifying times. It accepts time specification in hh:mm (hours:minutes) format for the current day. If the time has passed, it will be executed the next day. Of course, you can also use vague words such as midnight (late night), noon (noon), teatime (tea time, usually 4 p.m.) to specify the time. Users can also use a 12-hour timekeeping system, that is, add AM (morning) or PM (afternoon) after the time to indicate whether it is morning or afternoon. You can also specify the specific date of command execution in the format of month day (month day) or mm/dd/yy (month/day/year) or dd.mm.yy (day.month.year). The specified date must follow the specified time.

The above are all absolute timing methods. In fact, relative timing methods can also be used, which is very beneficial for arranging commands that will be executed soon. The specified format is: now + count time-units, now is the current time, time-units is the time unit, which can be minutes (minutes), hours (hours), days (days), weeks (weeks). count is the amount of time, whether it is days, hours, etc. Another timing method is to directly use today (today) and tomorrow (tomorrow) to specify the time to complete the command.

grammar

at [-V] [-q queue] [-f file] [-mldbv] time at -c job [job...]

Options

-f: Specify the task file containing specific instructions;
-q: Specify the queue name of the new task;
-l: Display the list of tasks to be executed;
-d: Delete the specified task to be executed;
-m: Send an email to the user after the task is completed.

Parameters

Date and time: Specify the date and time when the task will be executed.

Example

Three days later, execute /bin/ls at 5 pm:

[root@localhost ~]# at 5pm+3 days
at>/bin/ls
at> <EOT>
job 7 at 2013-01-08 17:00

Tomorrow at 17 o'clock, output the time to the specified file:

[root@localhost ~]# at 17:20 tomorrow
at> date >/root/2013.log
at> <EOT>
job 8 at 2013-01-06 17:20

After the scheduled task is set, we can use the atq command to check whether the system has executed the task before it is executed:

[root@localhost ~]# atq
8 2013-01-06 17:20 a root
7 2013-01-08 17:00 a root

Delete an already set task:

[root@localhost ~]# atq
8 2013-01-06 17:20 a root
7 2013-01-08 17:00 a root

[root@localhost ~]# atrm 7
[root@localhost ~]# atq
8 2013-01-06 17:20 a root

Display the task content that has been set:

[root@localhost ~]# at -c 8
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22 omit n characters here
date >/root/2013.log