1

I have vagrant boxes configured on a remote server (my-server in my example). I'm trying to run a set of remote commands on a vagrant box, from my machine, through an SSH session:

ssh me@my-server << "ENDSSH"

    cd /dir/to/vagrant

    vagrant status my_box
    vagrant ssh my_box -- "ls"

    echo "Good bye!"

ENDSSH

The first 3 commands are executed correctly, but the forth command is never executed. After the output of vagrant ssh my_box -- "ls" is printed, the SSH session is closed. This happens for any command that I attempt to run on my_box.

If I create a script containing the above commands, log into my-server and run the script manually, all the commands are executed including echo "Good bye!".

Is it possible that the vagrant ssh my_box -- "ls" produces an EOF which terminates the ssh session? Is there anyway to somehow catch the EOF token and then continue with the script?

Note: This question relates to another question I asked regarding bamboo. The plugin in bamboo I used to execute remote commands produces an Broken transport; encountered EOF error after executing some remote tasks.

Community
  • 1
  • 1
Ian2thedv
  • 2,691
  • 2
  • 26
  • 47
  • As a workaround, you might try exporting the vagrant ssh config to see if vanilla `ssh` avoids that hangup behavior http://stackoverflow.com/a/23685489/3385516 – mzulch Jan 19 '16 at 08:58
  • @mzulch thanks for the suggestion! Same behaviour though. This makes me think that ssh is to blame :/ – Ian2thedv Jan 19 '16 at 09:17
  • Disabling reading from stdin with the -n switch seems to fix it (I tested with `ssh` directly but I think `vagrant ssh my_box -- -n "ls"` should behave the same way). I don't fully understand why it works so there may be caveats involved. – mzulch Jan 19 '16 at 10:28
  • @mzulch that works with `vagrant ssh` as well! Seems like preventing it from reading from stdin fixes the issue! Thank you, if you answer I will gladly accept :) – Ian2thedv Jan 19 '16 at 10:52

1 Answers1

1

You can prevent the outer ssh session from disconnecting by preventing the inner ssh command from reading from stdin, using the -n switch (for reference, ssh man page)

vagrant ssh my_box -- -n "ls"
mzulch
  • 1,460
  • 12
  • 14