DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the UNIX system shell

Running commands at a later time with the batch and at commands

The batch and at commands allow you to specify a command or sequence of commands to be run at a later time. With the batch command, the system determines when the commands run; with the at command, you determine when the commands run. Both commands expect input from standard input (the terminal); the list of commands entered as input from the terminal must be ended by pressing <CTRL-d> (control-d).

The batch command is useful if you are running a process or shell program that uses a large amount of system time. The batch command submits a batch job (containing the commands to be executed) to the system. The job is put in a queue, and runs when the system load falls to an acceptable level. This frees the system to respond rapidly to other input and is a courtesy to other users.

The general format for batch is:

   batch
   first command
   	.
   	.
   	.
   last command
   <CTRL-d>
If there is only one command to be run with batch, you can enter it as follows:
   batch command_line

<CTRL-d>
The next example uses batch to execute the grep command at a convenient time. Here grep searches all files in the current directory and redirects the output to the file dol.file.
   $ batch
   grep dollar * > dol.file
   <CTRL-d>
   job 155223141.b at Tue Dec 3 11:14:54 1991
   $
After you submit a job with batch, the system responds with a job number, date, and time. This job number is not the same as the process number that the system generates when you run a command in the background.

The at command allows you to specify an exact time to execute the commands. The general format for the at command is:

   at time<
   first command
   	.
   	.
   	.
   last command
   <CTRL-d>

The time argument consists of the time of day and, if the date is not today, the date.

The following example shows how to use the at command to mail a happy birthday banner to the user with the login name emily on her birthday:

   $ at 8:15am Feb 27<
   banner happy birthday | mail emily
   <CTRL-d>
   job 453400603.a at Sat Feb 23 08:15:00 1991
   $
Notice that the at command, like the batch command, responds with the job number, date, and time.

If you decide you do not want to execute the commands currently waiting in a batch or at job queue, you can erase those jobs by using the -r option of the at command with the job number or you can save the job number by redirecting it. The general format is

   at -r job_number
Try erasing the previous at job for the happy birthday banner. Type:
   at -r 453400603.a
If you have forgotten the job number, the at -l command will give you a list of the current jobs in the batch or at queue, as the following screen shows:
   $ at -l
   user = mylogin 168302040.a at Mon Nov 25 13:00:00 1991
   user = mylogin 453400603.a at Sun Dec 08 08:15:00 1991
   $
Notice that the system displays the job number and the time the job will run.

Using the at command, mail yourself the file memo at noon, to tell you it is lunch time. (You must redirect the file into mail unless you use a ``here document,'' described in ``Shell programming''.) Then try the at command with the -l option.

   $ at 12:00pm
   mail mylogin < memo
   <CTRL-d>
   job 263131754.a at Jun 25 12:00:00 1991
   $ at -l
   user = mylogin 263131754.a at Jun 25 12:00:00 1991
   $

Next topic: Executing processes at regular intervals
Previous topic: Executing, stopping and restarting processes

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004