Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~/.bash_profile not being loaded? #77

Closed
lancejpollard opened this issue Sep 13, 2013 · 11 comments
Closed

~/.bash_profile not being loaded? #77

lancejpollard opened this issue Sep 13, 2013 · 11 comments

Comments

@lancejpollard
Copy link

Hey there, not sure if this is the best place to ask but I thought I'd try.

I just setup a basic micro instance on EC2 on ubuntu 12.04, and then installed node like this (modified from here):

sudo apt-get update
sudo apt-get install build-essential -y
sudo apt-get install g++ make libssl-dev git-core pkg-config
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bash_profile
. ~/.bash_profile

# Download Source for Node
mkdir ~/src
cd ~/src
git clone git://github.com/joyent/node.git

# Install Node:
cd ~/src/node
git checkout v0.10.17
./configure --prefix=~/local
make install

When I ssh into the instance and run node -v, it prints v0.10.17 as expected. I ssh like this:

ssh -i path/to/key.pem [email protected]

But when I try to do the same thing using this ssh2 module, it prints:

bash: node: command not found

The main difference between the two is this: when I ssh -i ..., it takes me to an interactive shell, whereas with node's ssh2 module I am executing the command (rather than running an interactive shell, I think, (exec vs. shell methods)). The strange thing is, using either method, if I cat ~/.bashrc, they both are exactly the same. The last thing is, I can successfully execute the node -v command on ssh2 if I add source ~/.bash_profile before, so:

source ~/.bash_profile ; node -v

The original install script echoed the PATH to ~/.bashrc, but I modified it to ~/.bash_profile because that was the only thing that seemed to work (along with adding the source ~/.bash_profile to the command).

Any ideas why this is happening? Is this something to do with ssh2 and ubuntu, or is this an issue with the node module?

@lancejpollard
Copy link
Author

It's also the same problem when executing a straight command from ssh (without interactive console):

$ ssh -i path/to/key.pem [email protected] "node -v"
bash: node: command not found

So I guess it's not. If anyone knows why this that would be super helpful. Anyways, closing the issue since it's probably unrelated.

@pkyeck
Copy link

pkyeck commented Feb 19, 2014

did you find a way around this? sourceing the profile/bashrc isn't working for me.

@mscdex
Copy link
Owner

mscdex commented Feb 19, 2014

@pkyeck You may have to check your .bashrc. At least on Ubuntu, .bashrc will exit early if it detects that it's not being run in interactive mode:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

You could try just setting PS1 before sourceing .bashrc:

conn.exec("PS1='\u@\h:\w\$ ' source ~/.bashrc; echo Hooray", function(err, stream) {
  // ...
});

@pkyeck
Copy link

pkyeck commented Feb 19, 2014

thanks for getting back.
I adjusted the .bashrc to include setup instructions when not run interactively.

@alansikora
Copy link

@pkyeck what you had to do to make that work?

@pkyeck
Copy link

pkyeck commented May 29, 2015

@alansikora easiest way for me right now is to use the connection.shell() function instead of connection.exec(). maybe give this a try (w/o adjusting the .bashrc)

@alansikora
Copy link

@pkyeck it works, but some of my method calls I need the result printed out so I can get it, and seems like the "shell" result is cluttered with some info I do not need. Any other ideias? Thank you, by the way! :D

@gdraganic
Copy link

@alansikora A little trick I use:

Set the interactive flag before source-ing .bashrc:

conn.exec("set -i && source ~/.bashrc && " + command, function(err, stream) {
  //...
});

@mscdex
Copy link
Owner

mscdex commented Mar 21, 2016

@gdraganic The set -i part shouldn't be necessary if you explicitly enable a pty (e.g. { pty: true }) in the exec() options.

@gdraganic
Copy link

@mscdex Didn't work for me even with pty enabled, this was my case:

conn.exec("set -i && source ~/.bashrc && " + command, {
  pty: true 
}, function(err, stream) {
  //...
});

This is the begging of my .bashrc file:

# If not running interactively, don't do anything                                                                                                                    
case $- in                                                                                                                                                           
    *i*) ;;                                                                                                                                                          
      *) return;;                                                                                                                                                    
esac 

Setting the interactive flag before source-ing the .bashrc file was the only way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants