Software Exercise 4.1: Passing Arguments Through the Wrapper Script

In this exercise, you will change the wrapper script and submit file from a previous exercise to use arguments. It builds on Exercise 2.2 from earlier, so only do this exercise if you've already done Exercise 2.2.

Background

In Exercise 2.2, the wrapper scripts had all files and options written out explicitly. However, imagine if you wanted to run the same job multiple times, or even just try out one or two different options or inputs. Instead of writing new wrapper scripts for each job, you can modify the script so that some of the values are set by arguments. Using script arguments will allow you to use the same script for multiple jobs, by providing different inputs or parameters. These arguments are normally passed on the command line:

But in our world of job submission, the arguments will be listed in the submit file, in the arguments line.

Identifying Potential Arguments

  1. Log into your account on the submit server where you ran Exercise 2.2 (learn.chtc.wisc.edu).
  2. Find the directory you used to submit Open BUGS jobs and open your run_openbugs.sh wrapper script.
  3. What values might we want to input to the script via arguments? Hint: anything that we might want to change if we were to run the script many times.

In this example, some values we might want to change are the name of the input and output file. These will be the arguments for our script.

Modifying Files

  1. Note the name of the input and output files and open the submit file. Add an arguments line if it doesn't already exist, and fill it with our two chosen arguments: the name of the input file and the name of the output file:

    arguments = input.txt results.txt
    
  2. Now go back to the wrapper script. Each scripting language (bash, perl, python, R, etc.) will have its own particular syntax for capturing command line arguments. For bash (the language of our current wrapper script), the variables $1 and $2 represent the first and second arguments, respectively. (If our script needed three arguments, we would use $3 for the third one). Thus, in the main command of the script, replace the file names with these variables:

    OpenBUGS < $1 > $2
    
  3. Once these changes are made, submit your jobs with condor_submit. Use condor_q -nobatch to see what the job command looks like to HTCondor.