自动克隆kvm虚拟机脚本,请各位指正,谢谢

回复 收藏
本帖最后由 loveyouhyf 于 2015-12-3 21:01 编辑

#! /bin/bash
##本脚本采取交互方式克隆输入的虚拟机名到输入的新的虚拟机并询问是否启动!
##写于2015-12-03
xmldir=/etc/libvirt/qemu/
read -p "please input the orivm of you wantto clone(copy) : " orivm
if [ -n $orivm ]&&[ -f $xmldir$orinm".xml" ] ; then
read -p "please input the newvm name: " newvm
if [ -n $newvm ]&&[ ! -f $xmldir$newvm".xml" ] ;then
orivmdir=`grep "source file=" $xmldir$orinm".xml"|awk -F "'" '{print $2}'`
vmdir=`echo ${orivmdir%/*}`
houzhui=`echo ${orivmdir##*.}`
/bin/cp $xmldir$orivm".xml" $xmldir$newvm".xml"
/bin/cp $orivmdir $vmdir"/"$newvm"."$houzhui
sed -i 's/'"$orivm"/"$newvm"'/g' $xmldir$newvm".xml"
sed -i '/uuid/'d $xmldir$newvm".xml"
virsh define $xmldir$newvm".xml"
read -p "the $newvm copy done,start it now? (y|n)" n
case $n in
[yY])   virsh start $newvm --console;;
[nN])   break;;
*)      echo "your intput error!";;
esac
else
echo "the $newvm existed!"
fi
else
echo "the $orivm not exist!"
fi

2015-12-03 20:58 举报
已邀请:
0

拉卡

赞同来自:

这个段位有点高了,得慢慢研究消化消化才行

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: