Delayed program execution in the background

Last revision August 9, 2004

Table of Contents:

  1. Shell interpretation
  2. Editing command lines
  3. Stuck in a Unix login session?
  4. Program execution
  5. Simple commands
  6. Unix command syntax
  7. Controlling processes
  8. Your login environment

The at program lets you set up a job to start running at a later time. To use this facility, make a file containing a list of the commands that you want to run, as if you were to type them at the terminal. Then run the at program, specifying a time when the job should start, and giving the name of the command file as an argument.

For example, to run a job to make a recursive listing of the entire /home/sysop file system at 3 a.m. the next day, you could create a file mycommands that contained the line

ls -lR /home/sysop > /scr1/username/listing

And then submit it to be started later with the command line:

at 3:00 mycommands

at uses a 24 hour clock. There are also formats for specifying particular days in the future. Read the manual entry.

at copies the contents of your command file to a system area, so you can erase that file after running the at program.

at recreates your login environment, including your current working directory and search path, before running the commands in your command file. However, the commands run by at no longer have access to your terminal. You must redirect all input and output away from the terminal and use files instead. This is especially important if your program will generate a lot of output.

If you do not redirect output to a file, the at program on pangea will collect your output and email it to you. If the output file is large (say, tens of megabytes), it could be rejected by the pangea email system for being too big and thus you would lose all output. Even if not rejected, it wastes space on the incoming email disk when you could send it directly to your home directory or scratch space (if large) by using output redirection for the commands listed in your at command file.

The at program allows an alternate syntax where the actual command to be run is specified right on the command line, rather than in a command file. The problem with this syntax is that it does not let you redirect the command input or output to a file. This is because any redirection symbol you type on the command line will be interpreted immediately by the shell, not when the command is actually run later by at. The shell thinks you are trying to redirect the input or output of the at program itself, rather than of the command which is to be executed later. Avoid problems by always using a command file to specify the commands to be run.

at has two options for listing and removing your scheduled jobs:

-l This option by itself, with no other arguments, lists the jobs you have submitted which have not yet run.
-r jobnumber This option, with no other arguments, allows you to remove your own pending job jobnumber from the queue, so it will not run. Use the -l option to see the job numbers.

<--Previous Overview Next-->

Comments or Questions?