Skip to content

Instantly share code, notes, and snippets.

@tfheen
Created June 12, 2012 10:42
Show Gist options
  • Save tfheen/2916838 to your computer and use it in GitHub Desktop.
Save tfheen/2916838 to your computer and use it in GitHub Desktop.
> cat .zshfunc/vnc
# -*- sh -*-
## vim:ft=zsh:foldmethod=marker
local HOST VM
if [ $# -lt 2 ]; then
echo "Usage: $0 HOST VM"
return
fi
HOST=$1
VM=$2
LPORT=$(( $RANDOM % 10000 + 5900))
VNCDISPLAY=$(ssh $HOST "gnt-instance list --no-headers -o name,network_port | awk '/^$VM/ { print \$2 - 5900 } END { exit 1; }' || virsh -c qemu:///system vncdisplay $VM | sed s/://")
ssh -N -f -L ${LPORT}:localhost:$(( $VNCDISPLAY + 5900 )) $HOST
gvncviewer localhost:$(( $LPORT - 5900 ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment