Search code examples
linuxtclredhatlsfmodulefile

Prevent exec command running on module unload ibm load sharing facilty


I have a tcl script which is a modulefile within the IBM Load Sharing Facitily (lsf) used to configure some environment variables and launch a python script by using the exec command.

When the module is unloaded normally the opposite of all the commands are run, but also the exec command is run as normal. I would like it so that the exec part is only run on module load and not on module unload.

Here is what I tried so far

if { !(is-loaded mymodule)} {
    exec .venv/bin/python mypython.py
}

I also tried this

if { module-info command load } {
    exec .venv/bin/python mypython.py
}

For each one I get a similar error

Module ERROR: invalid bareword "module"
in expression " module-info command [load] ";
should be "$module" or "{module}" or "module(...)" or ...

both exceptions complain either about an invalid bareword (either "is" or "module") depending on which snippet I try. Is my snytax invalid?


Solution

  • My syntax was incorrect, in the end I was able to solve the problem with the following:

    set is_load_command [module-info command load]
    
    if { $is_load_command == 1 } {
        exec .venv/bin/python mypython.py
    }
    

    I had two problems, correctly understanding comparisons in tcl and using return values from a called function. Neither really behaved how I am used to.