Skip to content

Exercise 5a: Pre and Post Commands

HTCondor provides the ability to run scripts before and/or after the main executable.

1. The PreCmd is used before running the executable :


2. The PostCmd is used after running the executable :


Both +PreCmd and +PostCmd take as an argument a string. The string is the name of the file that is to be run. These commands search for the file in the scratch directory on the executing machine and run it. For that reason is necessary first to send this file to the scratch directory.

The script runs before the executable The creates a simple file. It is very important to mention that the script is not going to be transferred automatically with the job, like the main executable, so it is necessary to define it in the transfer_input_files.

The script contains :


echo "Hello! I am exercise number 5 "> exercise05.txt
Create exercise5a.sub using the following:

    executable              =
    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/
    +PreCmd                 = ""

Execute condor_submit exercise5a.sub to submit the jobs.

In case the PRE script fails, the job will run normally. On the other hand, if the PRE script is not defined in the transfer_input_files, the job goes to the hold state.

Debugging Tip:

Hold state

If the job is in the hold state, the two basic reasons are:

  • There is an error in the submit file (paths and files that do not existed, permission problems, etc).
  • System problems.

By executing condor_q -hold, the reason for the job's hold state will be displayed.

Last update: November 26, 2019