8.4 Running One-time Tasks

8.4.1 Changing the Behavior of Batch Jobs

You can use the at command to schedule a one-time task to run at a specified time, or the batch command to schedule a one-time task to run when the system load average drops below 0.8. The atd service must be running to use at or batch.

# service atd status
atd (pid  2078) is running...

at takes a time as its argument and reads the commands to be run from the standard input. For example, run the commands in the file atjob in 20 minutes time:

# at now + 20 minutes < ./atjob
job 1 at 2013-03-19 11:25

The atq command shows the at jobs that are queued to run:

# atq
1	2013-03-19 11:25 a root

The batch command also reads command from the standard input, but it does not run until the system load average drops below 0.8. For example:

# batch < batchjob
job 2 at 2013-03-19 11:31

To cancel one or more queued jobs, specify their job numbers to the atrm command, for example:

# atrm 1 2

For more information, see the at(1) manual page.

8.4.1 Changing the Behavior of Batch Jobs

The load average of a system, as displayed by the uptime and w commands, represents the average number of processes that are queued to run on the CPUs or CPU cores over a given time period. Typically, a system might not considered overloaded until the load average exceeds 0.8 times the number of CPUs or CPU cores. On such systems, you would usually want atd to be able to run batch jobs when the load average drops below the number of CPUs or CPU cores, rather than the default limit of 0.8. For example, on a system with 4 CPU cores, you could set the load-average limit above which atd will not run batch jobs to 3.2.

If you know that a batch job typically takes more than a minute to run, you can also change the minimum interval that atd waits between starting batch jobs. The default minimum interval is 60 seconds.

To change the load-average limit and interval time for batch jobs:

  1. Edit /etc/init.d/atd, and add a line that defines the new load-average limit, minimum interval, or both in the OPTS variable for the atd daemon, for example:

    exec=/usr/sbin/atd
    OPTS="-b 120 -l 3.2"
    prog="atd"

    This example sets the minimum interval to 120 seconds and the load-average limit to 3.2.

  2. Restart the atd service:

    # service atd restart
    Stopping atd:                                              [  OK  ]
    Starting atd:                                              [  OK  ]
  3. Verify that the atd daemon is running with the new minimum interval and load-average limit:

    # ps -fC atd
    UID        PID  PPID  C STIME TTY          TIME CMD
    root      8359     1  0 12:06 ?        00:00:00 /usr/sbin/atd -b 120 -l 3.2

For more information, see the atd(3) manual page.