четверг, 30 августа 2012 г.

How to send key to running KVM guests from bash

I don't recommend this way, but I didn't found any another.

It works at rhel 6:


[root@virt ~]# LANG=C virsh version
Compiled against library: libvir 0.8.7
Using library: libvir 0.8.7
Using API: QEMU 0.8.7
Running hypervisor: QEMU 0.12.1


On ubuntu 10.04 virsh haven't command:
qemu-monitor-command

Some working shell to send strings:

#!/bin/bash


if [ "$#" = 0 -o "$1" = '--help' ]; then
        echo "Usage $(basename $0): <Domain> '<String>'"
        exit 66
fi

exec 1>/dev/null

MACHINE="$1"; shift

echo "$*" | grep -o . | while IFS= read key; do
        [ "$key" = " " ] && key='spc'
        [ ! -n "$key" ] && continue
        virsh qemu-monitor-command --hmp "$MACHINE" "sendkey $key"
done
virsh qemu-monitor-command --hmp "$MACHINE" 'sendkey kp_enter'