jyv*_*vet 3 ssh bash shell environment-variables environment-modules
的环境模块包被用于用户的环境(动态修改Debian软件包 environment-modules)。
我想module直接ssh从命令行使用。目的是能够从在前端节点上执行的 bash 脚本在不同的节点上执行命令。我不想为每个不同的节点配置显式更新PATH和LD_LIBRARY_PATH环境变量。
当我直接连接到节点然后module从节点调用时,它显然是工作的:
jyvet> ssh mynode
jyvet@mynode> module load gcc-6.0
jyvet@mynode> gcc --version
gcc (GCC) 6.0.1
Run Code Online (Sandbox Code Playgroud)
但是以下方法失败了:
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
Run Code Online (Sandbox Code Playgroud)
module由/etc/profile.d/modules.shwhich初始化/etc/profile(在 shell 启动时设置环境变量)。
该ssh命令执行shell是一个非交互的shell和既不呼叫/etc/profile,也没有读取配置文件。
这是解决方案:
jyvet> ssh mynode "source /etc/profile; module load gcc-6.0; gcc --version"
gcc (GCC) 6.0.1
Run Code Online (Sandbox Code Playgroud)
您还可以调用 的登录实例,bash以便在登录时自动/etc/profile.d/modules.sh进行source-ed:
ssh mynode "bash -lc 'module load gcc-6.0; gcc --version'"
Run Code Online (Sandbox Code Playgroud)