用case语句建立一个shell(功能是打开,关闭,重置,显示虚拟机)

#!/bin/bash

case "$1" in

start)                   /*当关键字为start时,执行打开虚拟机$2的语句

echo start $2 ...

virsh start $2 &> /dev/null

;;

poweroff)              /*当关键字为poweroff时,执行强制关闭虚拟机$2的语句

echo poweroff $2 ...

virsh destroy $2 &> /dev/null

;;

view)                /*当关键字为view时,执行显示虚拟机界面$2的语句

virt-viewer $2 &> /dev/null &

;;

reset)                /*当关键字为reset时,执行重启虚拟机$2

echo reset $2 ...

echo poweroff $2...

virsh destroy $2 &> /dev/null     /*强行关闭虚拟机$2

echo del $1.xml ...

virsh undefine $2 &> /dev/null    /*删除前端

echo create disk ...

qemu-img create -f qcow2 -b /var/lib/libvirt/p_w_picpaths/$2.img /var/lib/libvirt/p_w_picpaths/$2.img &> /dev/null                /*将硬盘快照一份

echo create $2 vm ...           

virt-install \              /*创建虚拟机

--name $2 \

--ram 1000 \

--disk /var/lib/libvirt/p_w_picpaths/$2.img \    /*创建硬盘目录

--import &> /dev/null &            /*导入图形界面

echo create $2 successful!!!

;;

*)

echo "error:please input reset|view|start|poweroff after three"

esac