Abstract
| Overview | |
|---|---|
| Goal | Schedule tasks to automatically execute in the future. |
| Objectives |
|
| Sections |
|
| Chapter Test |
|
at schedules future jobs.
atq lists scheduled jobs.
at -c inspects scheduled jobs.
atrm removes scheduled future jobs.
After completing this section, students should be able to schedule one-time tasks with at.
From time to time, an administrator (or end user) wants to run a command, or set of commands, at a set point in the future. Examples include the office worker who wants to schedule an email to his boss, as well as the system administrator working on a firewall configuration who puts a “safety” job in place to reset the firewall settings in ten minutes' time, unless he deactivates the job before then.
These scheduled commands are often called tasks or jobs.
One of the solutions available to users of a Red Hat Enterprise Linux system for scheduling future tasks is at. This is not a standalone tool, but rather a system daemon (atd), with a set of command-line tools to interact with the daemon (at, atq, and more). In a default Red Hat Enterprise Linux installation, the atd daemon will be installed and enabled automatically. The atd daemon can be found in the at package.
Users (including root) can queue up jobs for the
atd daemon using the command-line tool
at. The atd daemon provides 26
queues, a to z, with jobs in alphabetically later
queues getting less system priority (higher nice
levels, discussed in a later chapter).
Scheduling jobs
A new job can be scheduled by using the command at
<TIMESPEC>.
at will then read the commands to execute from
stdin. For larger commands, and typo-sensitive commands, it
is often easier to use input redirection from a script file, e.g.,
at now +5min < myscript, than typing all the
commands by hand in a terminal window. When entering commands by hand, you
can finish your input by pressing
Ctrl+D.
The allows for
many powerful combinations, giving users an (almost) free-form way of
describing exactly when a job should be run. Typically, they start with a
time, e.g., <TIMESPEC>02:00pm, 15:59, or even
teatime, followed by an optional date or number of days in the
future.
Some examples of combinations that can be used are listed in the following text. For a
complete list, see the timespec definition in the references.
now +5min
teatime tomorrow (teatime is 16:00)
noon +4 days
5pm august 3 2016
Inspecting jobs
To get an overview of the pending jobs for your user, use the command atq or, alternatively, the alias at -l.
Running this command gives the following output:
[student@desktopX ~]$atq28 Mon Feb 2 05:13:00 2015 a student 29 Mon Feb 3 16:00:00 2014 h student 27 Tue Feb 4 12:00:00 2014 a student
This shows four columns for every job scheduled to run in the future:
The job number, 28 in the first line.
The date and time scheduled for that job, Mon Feb 2 05:13:00
2015 in the first line.
The queue for the job, a in the first line, but
h in the second.
The owner of the job (and the user as which the job will run),
student in all our lines.
Normal, unprivileged users can only see and control their own jobs.
root can see and manage all jobs.
To inspect the actual commands that will run when a job is executed, use
the command at -c
<JOBNUMBER>. This output will
first show the environment for the job being set up
to reflect the environment of the user who created the job at the time it was created,
followed by the actual commands to be run.
Removing jobs
The atrm <JOBNUMBER>
will remove a scheduled job. This is useful when a job is no longer needed; for
example, when a remote firewall configuration succeeded, and
does not need to be reset.
at(1) and atd(8) man pages
/usr/share/doc/at-*/timespec