I am having an issue running a command remotely via a non-interactive SSH session to a Ubuntu 14.04. server.
I want to run a bundle command to execute a Jekyll build. If I SSH into an interactive shell on my server using ssh username@address
, and run:
cd /jekyll/site/dir ; /root/gems/bin/bundle exec jekyll build --incremental
It works successfully. However, If I try to run this from my local machine:
ssh username@address "cd /jekyll/site/dir ; /root/gems/bin/bundle exec jekyll build --incremental"
it fails. I have seen other issues, such as
- "Command not found via ssh with single command, found after connecting to terminal"
- "Why does an SSH remote command get fewer environment variables then when run manually?"
which explain that, in a non-interactive session, the environment might not be set up in the same way as an interactive session by default.
I tried adding some sourcing to the remote command to account for this:
ssh username@address "source /root/.profile ; source /root/.bashrc ; cd /jekyll/site/dir ; /root/gems/bin/bundle exec jekyll build --incremental"
Still, the bundle
command doesn't work correctly. The actual error that I get is:
/root/gems/bin/bundle:15:in `<main>': undefined method `b' for "exec":String (NoMethodError)
from /root/gems/bin/ruby_executable_hooks:24:in `eval'
from /root/gems/bin/ruby_executable_hooks:24:in `<main>'
Thus, the issue seems to have something to do with bundle/RVM, and perhaps there's some environment thing that I am still missing. I tried searching the web to determine why that error occurs, but I have not been able to pinpoint the issue.
If I cd
into the Jekyll site directory in an interactive session, it indicates that
"RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,"
and so on. Perhaps this has something to do with the way that RVM/Ruby/whatever overrides the cd
command to trigger that process, and maybe it isn't doing the same thing in the non-interactive session?