In Unix, what are at and batch, and how do I use them to submit non-interactive job requests?
Note: Currently, you cannot access the
at and batch commands on any UITS
central systems. However, LoadLeveler (available on Big Red
and the Libra Cluster) and TORQUE (available on
Quarry) are more robust options that provide the same
services. For more about LoadLeveler, see Getting started on Big Red and Using LoadLeveler on Libra at IU. For more about TORQUE, see What is TORQUE?
In Unix, the at and batch commands allow you
to schedule non-interactive tasks that execute, respectively, at a
specified time or as soon as system resources permit. Once a job is
completed, the system sends you mail messages containing the job's
output and errors, if any. Unlike crontab, at
and batch are generally used for jobs that are meant to
run only once.
Syntax
To submit a job with the at command, first enter:
at runtime
Replace runtime with the date and time you want to
execute the job. See "Setting the job execution time" below for more
information. Once you have pressed Enter or
Return, you may see a > or
at> prompt. However, there may be no
prompt at all. In any case, enter the command(s) and/or executable(s)
that you would like to execute. Once you have finished, press
Ctrl-d (or whatever your EOT character is). The system
should report that the job has been submitted.
The syntax for the batch command is identical except that
you do not set an execution time.
Setting the job execution time
With at, you must specify a time that the job should
execute. The format you use to indicate the time is very flexible and
may consist of the following:
| Time: | Enter a one- or two-digit number
(0-23) to indicate the start of an hour on a 24-hour clock (e.g., 13
is 13:00 or 1:00pm). To schedule the job to occur at a time other
than the start of the hour, add minutes (00-59), optionally separated
from the hour by a colon (e.g., 1334 or 13:34). You may follow the
number with an am or pm to indicate the
specific time on a 12-hour clock (e.g., 1:34pm or 0134pm). Finally,
you may also use the words now, noon, and
midnight to indicate the current time, 12:00pm, and
12:00am, respectively. If the time you indicate is later than the
current time and you haven't specified a date, the job will execute
the same day; otherwise, it will execute the next day.
|
| Date: | If you wish, you can schedule the job
to execute on a specific date. You may use keywords, such as
today, tomorrow, or one of the days of the
week. The job will then execute at the soonest possible date that
meets the requirements. You also may enter a fully qualified date,
such as November 9, 2009 . The year is optional and you may also use
abbreviations. As long as the date is unambiguous, your job request
will probably succeed.
|
| Increment: | You also can specify the
execution time by indicating how far in the future it should be,
relative to the current time. To do this, enter a plus sign
( + ) followed by a number and then one of the
following keywords: minutes, hours,
days, months, or years. For
example, assuming the current time is 12:00pm, the increment of
+2 weeks would set the execution time at noon on a day
two weeks hence.
|
These elements can be combined, as in the following examples:
at tuesday +2 hours
This would schedule the job for the following Tuesday at a time two
hours later than the current time.
at 9am February 2
In this case, the execution time will be 9:00 in the morning on
the second day of next February.
at 1334 +3 months
This job will run at 1:34pm on a date exactly three months from when
you used the at command.
Options
-f script |
Reads the commands to be executed from
the file script instead of from standard input
|
-l |
Lists the jobs you have queued; works only
with at, but jobs submitted with batch will
also be listed with this command (On some systems, this option has
been replaced by a separate command, atq.)
|
-m |
Sends you email notifying you the job has finished |
-r job-number |
Cancels the job whose ID is
job-number; works only with at, but jobs
submitted with batch can also be removed (On some
systems, this option has been replaced with a separate command,
atrm.)
|
Examples
at noon
tar -cf /users/dvader dvader.tar
Ctrl-d
In this example, the user submitted a job that will run at noon
the same day if submitted in the morning, or noon the next day if
submitted in the afternoon. When the task is performed, a tarball of
the /users/dvader directory will be created.
batch -f /home/hsolo/script1
In this case, rather than entering the commands into standard input,
the user submitted a batch command for a job that will
execute the script /home/hsolo/script1.
at -m 0530 November 9, 2009
/users/chewie/hb28.script
Ctrl-d
At 5:30am on November 9, 2009 the script hb28.script
will run. A mail message indicating that the script has been executed
will be sent to the user who submitted the job.
at -r skywalker.887664428.b
Here, the user has deleted the job skywalker.887664428.b.
For more information, consult the following man pages: at cron crontab
At Indiana University, to get support for personal or departmental Linux or Unix systems, see At IU, how do I get support for Linux or Unix?
Also see:
- In Unix, how can I get a command to execute when I log out?
- In Unix, how should I submit CPU-intensive jobs?
- In Unix, how do I cancel a batch job?
- In Unix, how can I send myself reminders of events?
- What are cron and crontab, and how do I use them?
- What is a batch job?
Last modified on August 22, 2008.






