C++ CSS HTML Java JavaScript MySQL Oracle PERL PHP SQL Unix VBScript XHTML XML Сети
At and Batch
 

28.3. At and Batch

While cron and anacron are used to schedule recurring tasks, the at command is used to schedule a one-time task at a specific time. The batch command is used to schedule a one-time task to be executed when the systems load average drops below 0.8.

To use at or batch you must have the at RPM package installed, and the atd service must be running. To determine if the package is installed, use the rpm -q at command. To determine if the service is running, use the command /sbin/service atd status.

28.3.1. Configuring At Jobs

To schedule a one-time job at a specific time, type the command at time, where time is the time to execute the command.

The argument time can be one of the following:

The time must be specified first, followed by the optional date. For more information about the time format, read the /usr/share/doc/at-<version>/timespec text file.

After typing the at command with the time argument, the at> prompt is displayed. Type the command to execute, press [Enter], and type Ctrl-D. More than one command can be specified by typing each command followed by the [Enter] key. After typing all the commands, press [Enter] to go to a blank line and type Ctrl-D. Alternatively, a shell script can be entered at the prompt, pressing [Enter]SHELL environment, the user's login shell, or /bin/sh (whichever is found first).

If the set of commands or script tries to display information to standard out, the output is emailed to the user.

Use the command atq to view pending jobs. Refer to Section 28.3.3 Viewing Pending Jobs for more information.

Usage of the at command can be restricted. Refer to Section 28.3.5 Controlling Access to At and Batch for details.

28.3.2. Configuring Batch Jobs

To execute a one-time task when the load average is below 0.8, use the batch command.

After typing the batch command, the at> prompt is displayed. Type the command to execute, press [Enter], and type Ctrl-D. More than one command can be specified by typing each command followed by the [Enter] key. After typing all the commands, press [Enter] to go to a blank line and type Ctrl-D. Alternatively, a shell script can be entered at the prompt, pressing [Enter]SHELL environment, the user's login shell, or /bin/sh (whichever is found first). As soon as the load average is below 0.8, the set of commands or script is executed.

If the set of commands or script tries to display information to standard out, the output is emailed to the user.

Use the command atq to view pending jobs. Refer to Section 28.3.3 Viewing Pending Jobs for more information.

Usage of the batch command can be restricted. Refer to Section 28.3.5 Controlling Access to At and Batch for details.

28.3.3. Viewing Pending Jobs

To view pending at and batch jobs, use the atq root user executes the atq command, all jobs for all users are displayed.

28.3.4. Additional Command Line Options

Additional command line options for at and batch include:

OptionDescription
-fRead the commands or shell script from a file instead of specifying them at the prompt.
-mSend email to the user when the job has been completed.
-vDisplay the time that the job will be executed.

Table 28-1. at and batch Command Line Options

28.3.5. Controlling Access to At and Batch

The /etc/at.allow and /etc/at.deny files can be used to restrict access to the at and batch commands. The format of both access control files is one username on each line. Whitespace is not permitted in either file. The at daemon (atdat or batch commands.

The root user can always execute at and batch commands, regardless of the access control files.

If the file at.allow exists, only users listed in it are allowed to use at or batch, and the at.deny file is ignored.

If at.allow does not exist, all users listed in at.deny are not allowed to use at or batch.

28.3.6. Starting and Stopping the Service

To start the at service, use the command /sbin/service atd start. To stop the service, use the command /sbin/service atd stop. It is recommended that you start the service at boot time. Refer to Chapter 14 Controlling Access to Services for details on starting the cron service automatically at boot time.

Главная