Continuing shell script execution after SSHing into guest machine?
This solved it. It's kind of hacky, but running
vagrant up && vagrant ssh -- -t 'cd /vagrant/rails_tutorial/sample_app; /bin/bash'
gets you in. For some reason vagrant keeps kicking you out if you don't launch the shell.
vagrant ssh --
allows you to pass commands into the SSH client. This is vagrant's own utility. The next flag, -t
is an SSH flag and it allows SSH to execute certain commands before it hands control back to you. You put your command after the -t
flag, but make sure to end it with <last command> ; /bin/bash
so that it launches a shell for you and you don't get kicked out.
you can also use Heredoc to run the commands after you ssh by using something similar to this in your script:
# Use heredoc to send script over ssh$ssh_cmd << 'END_DOC'cd <path>commandsexitEND_DOCecho $ssh_cmd