本帖最后由 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
#! /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
编辑回复