Last active
July 22, 2017 15:16
-
-
Save geedew/11289350 to your computer and use it in GitHub Desktop.
Copying files to a Vagrant VM from host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Change these settings to match what you are wanting to do | |
FILE=/File/To/Copy | |
SERVER=localhost | |
PATH=/Where/To/Put/File | |
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'` | |
scp ${OPTIONS} $FILE vagrant@$SERVER:$PATH |
To remove a trailing empty "-o = ", prepend the awk string with NF to filter out the blank line:
OPTIONS=`vagrant ssh-config | grep -v '^Host ' | awk -v ORS=' ' 'NF{print "-o " $1 "=" $2}'`
As the hostname and user are specified via the ssh config options, they don't need to be specified again. To copy a file from the host to a Vagrant VM:
scp ${OPTIONS} $FILE v:$PATH
to copy a file from a Vagrant VM to the host:
scp ${OPTIONS} v:$PATH $FILE
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I got a "Host directive not supported as a command-line option" with Vagrant 1.4.3, had to tweak a bit: