22.4. Scheduling a Job to Run on System Load Drop Using batch

To schedule a one-time task, also called a job, to run when the system load average drops below the specified value, use the batch utility. This can be useful for performing resource-demanding tasks or for preventing the system from being idle.
Users specify batch jobs using the batch utility. The jobs are then executed by the atd service.

22.4.1. Prerequisites for Batch Jobs

The batch utility is provided in the at package, and batch jobs are managed by the atd service. Hence, the prerequisites for batch jobs are the same as for at jobs. See Section 22.3.1, “Prerequisites for At Jobs”.

22.4.2. Scheduling a Batch Job

  1. A job is always run by some user. Log in as the desired user and run:
    ~]# batch
  2. At the displayed at> prompt, enter the command to execute and press Enter:
    ~]# batch
    at> sh /usr/local/bin/my-script.sh
    Repeat this step for every command you want to execute.

    Note

    The at> prompt shows which shell it will use:
    warning: commands will be executed using /bin/sh
    The batch utility uses the shell set in user's SHELL environment variable, or the user's login shell, or /bin/sh, whichever is found first.
  3. Press Ctrl+D on an empty line to finish specifying the job.

Note

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

Changing the Default System Load Average Limit

By default, batch jobs start when system load average drops below 0.8. This setting is kept in the atq service. To change the system load limit:
  1. To the /etc/sysconfig/atd file, add this line:
    OPTS='-l x'
    Substitute x with the new load average. For example:
    OPTS='-l 0.5'
  2. Restart the atq service:
    # systemctl restart atq

Viewing Pending Jobs

To view the list of pending jobs, use the atq command. See the section called “Viewing Pending Jobs”.

Deleting a Scheduled Job

To delete a scheduled job, use the atrm command. See the section called “Deleting a Scheduled Job”.

Controlling Access to Batch

You can also restrict the usage of the batch utility. This is done for the batch and at utilities together. See Section 22.3.2.1, “Controlling Access to At and Batch”.