Correct way to source .bashrc for non-interactive shell

夙愿已清 提交于 2021-01-20 08:57:10

问题


I have been trying to resolve problems to be able to run openmpi on multiple nodes.

Initially I had a problem with $PATH and $LD_LIBRARY_PATH variables not being updated from .bashrc file by openmpi session, so I manually added --prefix /path/to/openmpi to resolve this issue.

Turns out that even the anaconda path variables are not being loaded as well. So ultimately I need ~/.bashrc file to be sourced from my home directory. How can I do that? Can anyone help me out please?

UPDATE 01:

I wrote a simple shell script to check the version of python

python --version

and tried to run it with openmpi on local as well as remote machine as follows:

mpirun --prefix /home/usama/.openmpi --hostfile hosts -np 4 bash script

And it returns

Python 2.7.12
Python 3.6.8 :: Anaconda, Inc.
Python 3.6.8 :: Anaconda, Inc.
Python 2.7.12

Confirming my suspicion that whatever openmpi is doing to run remote processes doesn't invoke / set proper environment variables from the ~/.bashrc file. Any help from someone who has worked with multi-node openmpi?

UPDATE 02:

A simple ssh environment grep tell me that my environment variables are not updated which might be the cause of the problem. (I have even tried to set it up in ~/.ssh/environment file)

$ ssh remote-node env | grep -i path

It seems to be loading only the /etc/environment file with only basic paths setup. How to I rectify this?


回答1:


maybe you should run like this.I guess. two ways help you!

first:

mpirun --prefix /home/usama/.openmpi --hostfile hosts -np 4 . ~/.bashrc && bash script

second:

## 1. add this line to the script
. ~/.bashrc

## 2. run command as you do
mpirun --prefix /home/usama/.openmpi --hostfile hosts -np 4 bash script



来源:https://stackoverflow.com/questions/55990383/correct-way-to-source-bashrc-for-non-interactive-shell

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