Using bash autocompletion with IBM Spectrum LSF

With 25 years of development, IBM Spectrum LSF has a lot commands and options, and it can be a little challenging to remember the right option. Fortunately, Linux’s bash shell has a built in auto complete function that is triggered by double tapping the tab key. Even better, this can be extended to support other commands, such as LSF’s bsub and bjobs commands. For example:

# bsub -R[TAB][TAB] Runs the job on a host that meets the specified resource requirements.
# bsub –R

The LSF tab-help script illustrates a simple but powerful method for helping users to help themselves.

Enabling this in your cluster is an easy two-step process.

  1. First, you build the helper script.
    The file “” is a python script that is included in the “examples” directory in the LSF Fix Pack 3 update. This script takes the location of the LSF man pages as input, and iterates through the man pages generating summary messages for each command option. And produces “” as the output.
  2. Next, you source the “” file to provide tab-help. Or better still, install it in the “bash_completion.d” directory on your cluster hosts.

$ ./ -h
Usage: [ -p path | --manpath path ] [ -a | --all ] [ -s | --setup ] [ lsfcmd1 lsfcmd2 ... ]

-h, --help show this help message and exit
-a, --all generate hint message for all LSF commands
-s, --setup setup bash completion file to /etc/bash_completion.d/
-p MANPATH, --manpath=MANPATH
specify LSF man page path instead of auto detect, e.g, -p /opt/lsf/10.1/man
-o OUTPUT, --output=OUTPUT
specify output file path: e.g, /root/aaa

By default, the script uses $LSF_ENVDIR to get the location of the installed LSF man pages, and creates the bash completion script “” in the current working directory for bsub and bjobs.

bash-4.1$ ./
LSF tab help bash script '/tmp/' has been created successfully.
Either source the file or install it in /etc/bash_completion.d/ to use it.
bash-4.1$ source /tmp/
bash-4.1$ bsub -R

Runs the job on a host that meets the specified resource requirements.
bash-4.1$ bsub -R
bash-4.1$ bjobs -sum

Displays summary information about unfinished jobs.
bash-4.1$ bjobs -sum

Right now, the script can readily be extended to support other commands. You can customize the script itself to provide your own site-specific help and hint messages to your users.

Join The Discussion

Your email address will not be published. Required fields are marked *