skip to main content

Using PBS Variables

Many PBS jobs are very similar to each other, differing from previous jobs only by one or two parameters, like input filename. PBS allows scripts to use input parameters so scripts don’t have to be rewritten for every job.

An example job that demonstrates this is available on Maple at /usr/local/apps/example_jobs/pbs_variable_example

The main file is variable_example.pbs:
#PBS -N variable
#PBS -l mem=2gb
#PBS -l ncpus=1

cd $PBS_O_WORKDIR

echo "Input file: $INPUT_FILE"

# Run program here
ls -l $INPUT_FILE

The variable in this example is called INPUT_FILE. First, the script changes to the directory from which the script was submitted. Then it echos the value of the variable passed into the script. Finally, it runs a program on the input file, in this case, just ls.

This PBS script can be submitted by running:
qsub -v INPUT_FILE=file.csv variable_example.pbs

Starting multiple jobs at once

With some shell scripting, multiple jobs can be started at once. For instance, assume you had multiple CSV files that all needed to be processed by the same program. You could submit a separate for for each one by running:

for file in *.csv
do
qsub -vINPUT_FILE=$file variable_example.pbs
done

This code is included as launch_jobs.sh in the example job on Maple.