#!/bin/sh
#


# Loop running vms to shutdown
# For each one, send the ACPI shutdown command
# Allow 2 mins for shutdown
# If still has not shut down, kill the Bhyve vm process
# Then destroy the vm 

# Check if directory /dev/vmm exists. 
vminstancedir="/dev/vmm" 
if  [ ! -d "$vminstancedir" ]
then
	echo "Directory $vminstancedir not found.  "
	echo "No Bhyve vms to shutdown.  "  
else
	echo "Directory $vminstancedir exists.  "
	for FILE in /dev/vmm/*
		do
			vmname=$(echo "$FILE" | cut -d/ -f4 )
	echo "$vmname"
sh /tank/myscripts/stopvmgracefully.sh $vmname & 
		done
		fi





   #    for FILE in /dev/vmm/*
  #             do
 #                  ddd=$(echo "$FILE" | cut -d/ -f4 )
#echo $ddd
              # done


# guestname=$( echo "$line" | cut -f1 )
