全球主机交流论坛
标题:
共享一个XENSERVER的BASH...
[打印本页]
作者:
vpsoffer.com
时间:
2010-1-13 01:35
标题:
共享一个XENSERVER的BASH...
迅速清除VM的C盘.以模板系统的C盘代替..
其它盘不用动..
其效果..可想而知...
#!/bin/sh
#reset driver C
#write by bendy 67052 [at] qq.com
if [ -z "${XE}" ]; then
XE=xe
fi
# Check there's a vm uuid parameter to the command
if [ $# -ne 1 ]; then
echo "usage: $0 <vm_uuid_to_reset>"
exit 1
fi
vmuuid=$1
# Check if there's a VM by the uuid specified
${XE} vm-list params=uuid | grep -q " ${vmuuid}$"
if [ $? -ne 0 ]; then
echo "error: no vm uuid "${vmuuid}" found"
exit 2
fi
# Check the power state of the vm
name=$(${XE} vm-list uuid=${vmuuid} params=name-label --minimal)
state=$(${XE} vm-list uuid=${vmuuid} params=power-state --minimal)
wasrunning=0
# If the VM state is running, we shutdown the vm first
if [ "${state}" = "running" ]; then
${XE} vm-shutdown uuid=${vmuuid}
${XE} event-wait class=vm power-state=halted uuid=${vmuuid}
wasrunning=1
fi
# destroy OLD C
${XE} vbd-destroy uuid=`${XE} vbd-list vm-uuid=${vmuuid} device=hda | /usr/bin/perl -e 'while (<STDIN>) { if (/^uuid.* ([^ ]*)$/) { $uuid = $1; } } print "$uuid";'`
#echo "destroy ok"
# get drivce c uuid
viduuid=$(${XE} vbd-list device=hda | /usr/bin/perl -e 'while (<STDIN>) { if (/vdi-uuid.* ([^ ]*)$/) { $uuid = $1; } if ( $find ) { last;} if (/vm-name-label \( RO\): win/) { $find="yes" } } print "$uuid";')
#echo ${viduuid}
# clone driver C
newviduuid=$(${XE} vdi-clone new-name-label=clone uuid=${viduuid})
#echo "${newviduuid}"
# inst new vbd
${XE} vbd-create vm-uuid=${vmuuid} device=hda vdi-uuid=${newviduuid} bootable=true type=Disk mode=RW
复制代码
[
本帖最后由 vpsoffer.com 于 2010-1-13 01:37 编辑
]
作者:
cpuer
时间:
2010-1-13 01:39
标题:
回复 1# 的帖子
大晚上的都在呢
作者:
vpsoffer.com
时间:
2010-1-13 01:40
刚写好的东西..就共享到你的论坛了..看我多支持你...
作者:
vpsoffer.com
时间:
2010-1-13 01:42
不过这东西..我还是有一点点的保留.....看不懂的就算了...
同行竞争大啊....原谅我小小的自私
作者:
cpuer
时间:
2010-1-13 11:47
标题:
回复 4# 的帖子
额,我看不懂。
欢迎光临 全球主机交流论坛 (https://sunk.eu.org/)
Powered by Discuz! X3.4