Created
February 7, 2012 12:33
-
-
Save nibalizer/1759501 to your computer and use it in GitHub Desktop.
Poor mans virt-viewer
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 | |
# Short shell script to connect to a remote libvirt vm. Best when run | |
# under an ssh agent and the user must be in libvirtd on the hypervisor | |
VNC_COMMAND="(/Applications/Chicken\ of\ the\ VNC.app/Contents/MacOS/ && \ | |
./Chicken\ of\ the\ VNC \$VNC_COMMAND_ARGS &)" | |
HYPERVISOR=$2 | |
VM=$1 | |
USER=${3:-`who am i | cut -d " " -f 1`} | |
echo "Connecting to $VM on $HYPERVISOR" | |
VNC_PORT_LOCAL=5900 | |
VNC_DISPLAY_LOCAL=0 | |
until [ -z "`lsof -i:$VNC_PORT_LOCAL`" ]; do | |
echo "Port $VNC_PORT_LOCAL in use: inrcrementing" | |
let VNC_PORT_LOCAL+=1 | |
let VNC_DISPLAY_LOCAL+=1 | |
done | |
VNC_DISPLAY_REMOTE=`ssh -l $USER $HYPERVISOR "virsh vncdisplay $VM | cut -d ":" -f 2"` | |
VNC_PORT_REMOTE=5900 | |
let VNC_PORT_REMOTE+=$VNC_DISPLAY_REMOTE | |
echo ssh -L $VNC_PORT_LOCAL:localhost:$VNC_PORT_REMOTE -l $USER -N -f $HYPERVISOR | |
ssh -L $VNC_PORT_LOCAL:localhost:$VNC_PORT_REMOTE -l $USER -N -f $HYPERVISOR | |
VNC_COMMAND_ARGS="localhost:${VNC_PORT_LOCAL:-0}" | |
echo VNC_COMMAND $VNC_COMMAND | |
echo VNC_COMMAND_ARGS $VNC_COMMAND_ARGS | |
(cd /Applications/Chicken\ of\ the\ VNC.app/Contents/MacOS/ && ./Chicken\ of\ the\ VNC $VNC_COMMAND_ARGS &2>1 > /dev/null &) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment