I'm trying to pass a simple command to the vagrant machine.
vagrant ssh -c "mysql -u root -e'CREATE DATABASE testing';"
The db doesn't get created. Instead I just get 'logged in' to the vagrant machine via ssh.
The same thing happens when I run
vagrant ssh -c "touch test.txt"
I've also tried with:
--command
instead of shorthand -c
Any ideas what's going on?
Edit
I'm going to distribute my script and it's going to integrate my script with Homestead, so can't really tweak the vagrant configuration.
Edit
Since I'm using Homestead the user and pw is different. It should have been
vagrant ssh -c "mysql -u homestead -psecret -e'CREATE DATABASE testing;'"
not changing the code above to avoid confusion with already submitted answers.
But nonetheless, this does not solve the problem. The same thing is happening as described above.
Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!
Command: vagrant ssh [name|id] [-- extra_ssh_args] This will SSH into a running Vagrant machine and give you access to a shell.
Command: vagrant box update This command updates the box for the current Vagrant environment if there are updates available. The command can also update a specific box (outside of an active Vagrant environment), by specifying the --box flag. Note that updating the box will not update an already-running Vagrant machine.
This works
vagrant ssh -- -t 'touch test.txt'
The flag -t creates a pseudo-tty for bash to use. Which is a variation on the answer to this question.
Running remote commands after vagrant ssh
Which is explained in more detail here.
https://unix.stackexchange.com/questions/119894/single-command-to-login-to-ssh-and-run-program/119899#119899
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With