SSH to remote host when the virtual machine start

161 views
Skip to first unread message

Pavel Lautsevich

unread,
Feb 23, 2016, 12:11:12 PM2/23/16
to Vagrant
I need to connect via SSH to a remote host when a virtual machine starts, run there some commands and close the connection. I'm trying to do it using the following bootstrap.sh script:

#!/usr/bin/env bash
sudo su
apt-get install sshpass
sshpass -p 'password' ssh -o StrictHostKeyChecking=no user...@server.example.com
#some commands go here
exit

The system
responds
:

==> default: Pseudo-terminal will not be allocated because stdin is not a terminal.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.


The command "sshpass -p 'password' ssh -o StrictHostKeyChecking=no user...@server.example.com" works well when i type it after manual "vagrant ssh".

What am I doing wrong?


I would be grateful for any advice!

Alvaro Miranda Aguilera

unread,
Feb 23, 2016, 9:21:31 PM2/23/16
to vagra...@googlegroups.com
Hello

sudo su what does?

you can use sudo to run commands as other user, but sudo su not sure what will do

if you want to run a command as root, vargrant usually does, so you could remove that.

Try:

(note -l next to bash)


#!/usr/bin/env bash -l
sudo -E -H apt-get -y install sshpass
sshpass -p 'password' ssh -o StrictHostKeyChecking=no user...@server.example.com <<EOF

#some commands go here
exit
EOF


Thanks
Alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/91fdc505-50e9-4b29-af21-d429c19b634d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages