#! /bin/sh domain=winxp while : ; do env LANG=C.utf8 LC_ALL=C.utf8 LANGUAGE=C.utf8 \ VIRSH_DEFAULT_CONNECT_URI=qemu:///system \ virt-viewer -w -f -a --domain-name "$domain" # check if guest is still running. If not, exit the loop. virsh list --name | grep -q "$domain" || break # guest is still running, check stop file. If stop file # exists, just leave the loop. test -f /etc/virtlauncher.nopoweroff && break done ! test -f /etc/virtlauncher.nopoweroff && sudo /usr/sbin/poweroff