Skip to content

Instantly share code, notes, and snippets.

@xpepper
Created December 30, 2021 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpepper/51010329cddb4efd82b266e28d4d23c3 to your computer and use it in GitHub Desktop.
Save xpepper/51010329cddb4efd82b266e28d4d23c3 to your computer and use it in GitHub Desktop.
A shell script to execute a command on a vagrant machine (e.g. ./asvagrant.sh ls)
(
relativeDir=""
while [[ ! -d ".vagrant" ]]; do
if [[ "$(pwd)" == "/" ]]; then
echo "Not a valid path"
exit
fi
relativeDir="${PWD##*/}/$relativeDir"
cd ..
done
ssh -t vagrant@localhost -p 2222 -i ".vagrant/machines/default/virtualbox/private_key" "shopt -s expand_aliases; source /etc/profile.d/env.sh; source ~/.bash_aliases; cd /vagrant/$relativeDir; eval $@"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment