Running AMLs in the background or at a later time

To run any UNIX process in the background, add an & at the end of the command line. But please do not use this to run several AMLs at once, especially during lab times. Running things at a given time in the future is a much better idea, especially since you can run them in the middle of the night.

Using at

The first thing you need to understand is that you don't run AMLs directly using at, but you call them from a UNIX script. A UNIX script is simply another macro language like AML that works with UNIX commands. There's a lot to UNIX scripts, but we'll just use some very simple methods. All we need to put in our script is:
  1. something to tell UNIX to use the C shell (the user interface that Arc requires, and is identified with the '%' prompt);
  2. a command to run the AML (or multiple commands to run multiple AMLs); and
  3. something to tell us how long the process took (not actually required, but useful information).
Let's say we have an AML called model.aml and we want to run it at 2 am. We'd start by creating a script (using a text editor like pico) we'll call runit, with the features listed above included. It would look like this:

#
date >model.out
arc '&r model' >>model.out
date >>model.out
The first line specifies this is a C-shell script, the two dates produce a date & time string, which are both sent to the output file model.out, and the aml is run with its screen output also appended to the output file. Note: In order to run this script as a command, it must be executable. In UNIX, a file can be made executable by setting it so with chmod:
% chmod +x runit

Now we could either run it by entering runit, or we can make it run at 2 am:

% at 2:00 runit

You can also specify a date and year, but if you specify a time that is before the current time, the date is assumed to be tomorrow.

Give it a try!


Other uses for this script

You might consider just using this script as your "calling AML" -- just run each in turn:

#
date >model.out
arc '&r setup' >>model.out
arc '&r step1' >>model.out
arc '&r step2' >>model.out
date >>model.out
There is one minor catch to this: if you're starting from the beginning, and thus your workspace isn't created yet, your later steps will need to have a statement that goes to the correct workspace (w {workspace}) just as the setup.aml does. If you're running the script from within your workspace, you obviously don't want to do this. The lesson is simply to be aware of what you're doing and where you're doing it in terms of directory space.

Recommendation: Put the Workspace setting in all of your steps, and always run your AML steps from the scripts in your home directory (or wherever you originally created your AMLs, one level above your workspace), as shown above (and as shown below, slightly modified).

You might also want to have the screen output (standard output) go to different text files, so you can see where something went wrong:

#
date >date.out
arc '&r setup' >setup.out
arc '&r step1' >step1.out
arc '&r step2' >step2.out
date >>date.out
Of course, there are all kinds of variations you might want to experiment with -- maybe you want to know the time each step took, so you might run date between each step.
Return to Arc Tricks page
Return to Modeling Index