xyp5ow
Last Updated: February 23, 2017
·
7.424K
· blainesch
Ffebdf905fae3278a260ed03c9d165c7

Sending Command to Vagrant - Undocumented Flag

Often times we want to run a single command in Vagrant, but doing this seems to take too long:

-> vagrant ssh
Last login: Fri Jul 12 14:55:21 2013 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.

-> sudo service httpd restart
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]

-> exit

Instead, why not send the single command straight to Vagrant. Using the undocumented "-c" flag you can send a command straight to vagrant.

-> vagrant ssh -c 'sudo service httpd restart'
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]
Say Thanks
Respond

3 Responses
Add your response

7894
533b687cf97f813c620703e41c215fd7
over 1 year ago ·
7896
Ffebdf905fae3278a260ed03c9d165c7

@walesmd I'm not sure how long it's been on those documents, but they still don't show up when I do vagrant --help or man vagrant. Thanks for letting me know!

over 1 year ago ·
8002

For help on any individual command run vagrant COMMAND -h
For example: vagrant ssh -h
Usage: vagrant ssh [vm-name] [-c command] [-- extra ssh args]

-c, --command COMMAND            Execute an SSH command directly.
-p, --plain                      Plain mode, leaves authentication up to user.
over 1 year ago ·
Filed Under