6

The Environment Modules package is used for dynamic modification of a user's environment (debian package environment-modules).

I would like to use module directly from a ssh command line. The purpose is to be able to execute commands on different nodes from a bash script executed on a front node. I don't want to explicitly update PATH and LD_LIBRARY_PATH environment variables for each different node configuration.

When I directly connect to the node and then call module from the node, it is obviously working:

jyvet> ssh mynode
jyvet@mynode> module load gcc-6.0
jyvet@mynode> gcc --version
gcc (GCC) 6.0.1

But the following approach fails:

jyvet> ssh mynode "module load gcc-6.0; gcc --version"
command not found: module
gcc-4.8 (Debian 4.8.4-1) 4.8.4
jyvet
  • 2,021
  • 15
  • 22

2 Answers2

7

module is initialized by /etc/profile.d/modules.sh which is called by /etc/profile (which sets the environment variables at startup of the shell).

The ssh command execution shell is a non-interactive shell and does neither call /etc/profile, nor read config files.

Here is the solution:

jyvet> ssh mynode "source /etc/profile; module load gcc-6.0; gcc --version"
gcc (GCC) 6.0.1
jyvet
  • 2,021
  • 15
  • 22
5

You can also invoke an login instance of bash so that the /etc/profile.d/modules.sh is source-ed automatically while login:

ssh mynode "bash -lc 'module load gcc-6.0; gcc --version'"
heemayl
  • 39,294
  • 7
  • 70
  • 76