Connect to Virtual Machine Console from XenServer Command Line

Simple shell script to help with connecting to VM console from the command line.

#!/bin/sh
#
# vm-console.sh
#
DOMID=$(xe vm-list uuid=$1 params=dom-id --minimal)
HOSTUUID=$(xe vm-list uuid=$1 params=resident-on --minimal)
NAMELABEL=$(xe host-list uuid=$HOSTUUID params=name-label --minimal)
XL=$(which xl)
MYHOSTNAME=$(hostname)

if [ "${MYHOSTNAME}-" == "${NAMELABEL}-" ]; then
        echo "locally resident"
        
	ps aux | grep vnc | grep "/$DOMID/" | awk '{print $2}' | xargs kill >/dev/null 2>/dev/null
        echo "Connecting, use Ctrl-] to disconnect."
        
	$XL console $DOMID
else
        echo "resident on $NAMELABEL, domid=$DOMID"
fi

A session would something like this.

[[email protected] ~]# ./vm-console.sh 2718f399-e4b5-cbcc-e924-c9464ccaf343
locally resident
Connecting, use Ctrl-] to disconnect.
login: timed out after 60 seconds

dev login:

The script can be found in the Downloads section.

Nov 7th, 2017 • Posted in XenServer
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>