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 :

  +PreCmd
  +PreArguments

2. The PostCmd is used after running the executable :

  +PostCmd
  +PostArguments

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 ex_05.sh script runs before the executable welcome.sh. The ex_5.sh creates a simple file. It is very important to mention that the script ex_05.sh is not going to be transferred automatically with the job, like the main executable welcome.sh, so it is necessary to define it in the transfer_input_files.

The script ex_05.sh contains :

#!/bin/bash

echo "Hello! I am exercise number 5 "> exercise05.txt

Create exercise5a.sub using the following:

    executable              = welcome.sh
    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 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.