The batch
command is used to execute scheduled commands or tasks when the system is not busy. It is similar to the at
command, but it waits for the system to be idle before executing the scheduled tasks. This makes it a useful tool for scheduling tasks that are not time-sensitive and can be executed when the system is not in use.
Overview
The syntax for the batch
command is as follows:
batch [options] [file]
The file
argument specifies the file containing the commands to be executed. If no file is specified, batch
reads commands from standard input.
By default, batch
schedules the commands to be executed when the system load average drops below 1.5. This value can be changed using the -l
option.
Here’s an example of how to use the batch
command:
$ echo "echo 'Hello, world!'" | batch
This command schedules the echo 'Hello, world!'
command to be executed when the system load average drops below 1.5.
You can also specify a specific time for the command to be executed using the -t
option:
$ echo "echo 'Hello, world!'" | batch -t 1200
This command schedules the echo 'Hello, world!'
command to be executed at 12:00 pm.
Options
Here are the available options for the batch
command:
Option | Description |
---|---|
-f file |
Read commands from file instead of standard input. |
-l load_average |
Schedule commands when the system load average drops below load_average . The default value is 1.5. |
-q queue |
Use the specified queue for scheduling. The default queue is batch . |
-t time |
Schedule commands to be executed at the specified time . The time argument can be in the format hh:mm or hhmm . |
Troubleshooting tips
If the scheduled commands are not executing as expected, check the system load average using the uptime
command. If the load average is above the value specified with the -l
option, the commands will not be executed until the load average drops below that value.
If the commands are still not executing, check the system logs for any error messages related to the batch
command.
Notes
- The
batch
command is part of theat
package and may not be installed by default on all Linux distributions. - The
batch
command can be used in conjunction with theat
command to schedule commands to be executed at a specific time or when the system is not busy.