0

On GCE, I have 3 VMs and I can use ssh to access them from one of them.
I've installed Cassandra on them and configured PATH environment variable in ~/.bash_profile.

~/.bash_profile:

PATH=$PATH:$HOME/.local/bin:$HOME/bin
export CASSANDRA_HOME=/opt/apache-cassandra-3.11.1
export SPARK_HOME=/opt/spark-2.1.2-bin-hadoop2.7
PATH=$PATH:$CASSANDRA_HOME/bin:$SPARK_HOME/bin:$SPARK_HOME/sbin
export PATH

Running echo $PATH and getting /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/nmj/.local/bin:/home/nmj/bin:/opt/apache-cassandra-3.11.1/bin:/opt/spark-2.1.2-bin-hadoop2.7/bin:/opt/spark-2.1.2-bin-hadoop2.7/sbin means it's correct.

But when running pssh -h hosts.txt -l nmj -i 'echo $PATH', I only got /usr/local/bin:/usr/bin.
$PATH looks incorrect here.

So I couldn't use pssh to execute ssh in parallel to start up cassandra, like pssh -h hosts.txt -l nmj -i cassandra, because of bash: cassandra: command not found.

How to configure $PATH correctly?

Solution:
In my opinion, pssh will start a non-login shell. So it'll not load ~/.bash_profile file. Then when I defined these variables in ~/.bashrc file, it worked.

niaomingjian
  • 113
  • 6

1 Answers1

2

Your answer might be here Why does the $PATH of an ssh remote command differ from that of an interactive shell?

Basically, because you're running a command as an argument, you are not actually opening a shell, so the files are not loaded, and the PATH variable is loaded with those files.

What you could do is source these files before running the cassandra command, and it may work

/etc/bashrc
/etc/profile
~/.bash_profile
Diego Velez
  • 825
  • 1
  • 7
  • 13
  • Following your suggestion, this command worked for me where my .bashrc defines a custom $PATH, aliases etc. I'm using under Ubuntu 21.04: pssh -i -h hosts "source /home//.profile; source /home//.bashrc; mycommand" – Chris Smith Jul 21 '21 at 16:42