Created
December 29, 2017 22:01
-
-
Save naingyeminn/2bba5baa6955554872005284cf45af38 to your computer and use it in GitHub Desktop.
SSH Login to VBox Headless
This file contains hidden or 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 | |
aname=$1 | |
vm=$2 | |
vmauth=$3 | |
if [ -n "$4" ]; then | |
port=$4 | |
else | |
port=22 | |
fi | |
rcfile="$HOME/.${SHELL##*/}rc" | |
aliaschk=$(grep "^alias $aname" $rcfile) | |
if [ -z "$aliaschk" ]; then | |
echo "alias $aname='if VBoxManage showvminfo \"$vm\" | grep State | grep running > /dev/null; then ssh $vmauth -p $port; else VBoxManage startvm $vm --type headless; while true; do ssh -q $vmauth -p $port exit && break; done; ssh $vmauth -p $port; fi'" >> $rcfile | |
echo "Ok" | |
else | |
echo "Alias exists" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment