Skip to content

Exercise 5b: Passing Information

In this exercise the script ex_05.sh will be reused for the PreCmd. A file is created by the PreCmd before the execution of ex_05.py, so the executable can take the created file exercise05.txt as an argument.

The script ex_05.sh contains the following code:

#!/bin/bash

echo "Hello! I am exercise number 5 "> exercise05.txt
The script ex_05.py takes the file and prints all the lines of the file.
#!/usr/bin/env python
import sys

input_filename = sys.argv[1]
print "The name of the file is ", input_filename

input_file = open(input_filename, 'r')
for line in input_file:
    print line
input_file.close()
Create exercise5b.sub using the following:

    executable              = ex_05.py
    arguments               ="exercise05.txt"
    output                  = output/ex_05.$(ClusterId).$(ProcId).out
    error                   = error/ex_05.$(ClusterId).$(ProcId).err
    log                     = log/ex_05.$(ClusterId).log

    transfer_input_files    = your_path/ex_05.sh
    +PreCmd                 = "ex_05.sh"

    queue
Execute condor_submit exercise5b.sub to submit the jobs.

It is very useful to use the output of the PreCmd command if the jobs have dependencies. In such cases it maybe preferable to use DAGs (see exercise 8).

Note: If the initialdir is defined and one of the files that exist in the directory is used in PreCmd command, jobs will fail. It will go to the hold state because execute machine will not find the file in its pool directory. Here is necessary to use the transfer_input_files in order to copy the file to execute machine.

    executable              = ex_05.py
    arguments               ="exercise05.txt"
    output                  = output/ex_05.$(ClusterId).$(ProcId).out
    error                   = error/ex_05.$(ClusterId).$(ProcId).err
    log                     = log/ex_05.$(ClusterId).log

    initialdir              = your_path/ex_05.sh
    +PreCmd                 = "ex_05.sh"

    queue

Last update: November 26, 2019