Last active
November 21, 2023 03:27
-
-
Save colindean/5213685 to your computer and use it in GitHub Desktop.
A quick way to transfer a file to the home directory on a Vagrant VM
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 | |
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'` | |
scp ${OPTIONS} "$@" || echo "Transfer failed. Did you use 'default:' as the target?" |
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/bash | |
PORT=2222 | |
if [ ${VAGPORT} ]; then | |
PORT=${VAGPORT} | |
fi | |
VAGRANT_GEM=$(dirname `gem which vagrant`)/.. | |
VAGRANT_KEY=${VAGRANT_GEM}/keys/vagrant | |
chmod 600 ${VAGRANT_KEY} | |
ssh -i ${VAGRANT_KEY} -p ${PORT} vagrant@localhost | |
#need to test this: | |
#OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`; | |
#ssh ${OPTIONS} localhost |
Thanks @spyderman4g63. the shared vagrant folder was all I needed
Thank you @spyderman4g63. It works like a charm. Most easiest solution :)
@colindean thanks for this. really useful! learn something new every day!
I added NF
to skip blank lines, not sure if would be a problem in the long run but you can avoid a trailing -o = %
... IdentitiesOnly=yes -o LogLevel=FATAL -o = %
Also works nicely with rsync:
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' 'NF {print "-o " $1 "=" $2}'`
rsync -avz -e "ssh ${OPTIONS}" default:/tmp/test.txt ~/Downloads/
Thanks @geedew easiest answer I've found
Thanks @spyderman4g63 extremely easy way!
@spyderman4g63 👍 thanks!!
I get Host directive not supported as a command-line option
error.
Solution is here https://gist.github.com/geedew/11289350
OPTIONS=`vagrant ssh-config | grep -v '^Host ' | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`
For those who need sudo
privilege, try $ vagrant sudo-rsync
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@colindean Thanks for the script.
usage: ./vagrant-scp.sh myfile.txt default: