LinuxCommandLibrary

batch

Schedule commands for execution when system load permits

TLDR

Execute commands from stdin (press when done)

$ batch
copy

Execute a command from stdin
$ echo "[./make_db_backup.sh]" | batch
copy

SYNOPSIS

batch

PARAMETERS

(no direct command-line options)
    The batch command itself does not accept command-line options. It expects the commands to be executed to be provided via standard input (e.g., piped from another command or typed directly) or redirected from a file.

DESCRIPTION

batch is a utility within the at job scheduling system used to execute commands when the system's load average falls below a specific threshold, typically 0.8. Unlike at, which schedules jobs for a precise future time, batch prioritizes system resource availability, making it ideal for non-time-critical but resource-intensive tasks. Commands are read from standard input or a redirected file. When a batch job is submitted, the current working directory, environment variables (except TERM, TERMCAP, DISPLAY, and _), and umask are preserved. The job is then executed by the atd daemon using the user's login shell or /bin/sh. Any output (stdout and stderr) is mailed to the user by default, unless explicitly redirected to a file or /dev/null. This command ensures that heavy tasks do not negatively impact foreground interactive sessions or critical system services.

CAVEATS

Execution is not guaranteed at a specific time; it depends entirely on the system's fluctuating load average.
The default load threshold (often 0.8) for job execution is configurable via the atd daemon's settings and may vary by system.
The environment (PATH, variables, umask) captured at the time of job submission is used, not at the time of execution. Ensure your job script is self-contained or relies on a robust environment.
By default, command output is mailed to the user, which can lead to email clutter if not handled by explicit redirection.

SUBMITTING A JOB

Commands can be submitted to batch in a few ways:
1. Type commands directly:
batch
command1
command2
...
Ctrl+D (to signal end of input)
2. Pipe commands:
echo 'ls -l /tmp' | batch
3. Redirect from a script file:
batch < /path/to/script.sh

LOAD THRESHOLD

The system load average threshold at which batch jobs are executed is typically 0.8. This value is configurable within the atd daemon's settings, often in a configuration file like /etc/at.conf or determined by compile-time options. The atd daemon constantly monitors the system load and executes pending batch jobs as soon as the load drops below this configured threshold.

HISTORY

The batch command is an integral part of the at utility suite, which has been a fundamental component of Unix and Unix-like operating systems for many decades. Its core functionality for scheduling one-off tasks dates back to early Unix versions, providing a simple yet effective mechanism for deferred execution. batch specifically addresses the need for opportunistic execution, allowing tasks to run when system resources are ample, thus avoiding performance degradation during peak load. This focus distinguishes it from at's time-specific scheduling and has kept it relevant for system administrators managing resource-sensitive operations.

SEE ALSO

at(1), atq(1), atrm(1), cron(8), nice(1), renice(1)

Copied to clipboard