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 “lsfhint.py” 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 “lsfhint.sh” as the output.
  2. Next, you source the “lsfhint.sh” file to provide tab-help. Or better still, install it in the “bash_completion.d” directory on your cluster hosts.

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

Options:
-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 “lsfhint.sh” in the current working directory for bsub and bjobs.

bash-4.1$ ./lsfhint.py
LSF tab help bash script '/tmp/lsfhint.sh' has been created successfully.
Either source the file or install it in /etc/bash_completion.d/ to use it.
bash-4.1$ source /tmp/lsfhint.sh
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 lsfhint.py 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 *