How to use environment modules in a ssh command line?

天涯浪子 提交于 2019-12-12 02:53:49

问题


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

回答1:


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



回答2:


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'"


来源:https://stackoverflow.com/questions/36728685/how-to-use-environment-modules-in-a-ssh-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!