#!/bin/bash VMNAME=rhel5 IPADDRESS=192.168.0.100 VMFILE=/etc/xen/rhel5.xml TIMEOUT=300 STATE=1 virsh shutdown $VMNAME > /dev/null 2>&1 rc=$? [ $rc -ne 0 ] && exit $STATE before=$(date +%s) now=$(date +%s) while [ $((now - before)) -le $TIMEOUT ] do virsh domstate $VMNAME > /dev/null 2>&1 rc=$? if [ $rc -eq 1 ]; then STATE=0 break fi now=$(date +%s) sleep 1 done if [ $STATE -ne 0 ]; then virsh destroy $VMNAME > /dev/null 2>&1 fi exit $STATE