从 VBoxManage list runningvms 中获取的当前运行中虚拟机列表,遍历一个个关闭,可以指定关闭方式:pause|resume|reset|poweroff|savestate|acpipowerbutton|acpisleepbutton,默认为 savestate。
#!/bin/sh
act="savestate"
args="pause|resume|reset|poweroff|savestate|acpipowerbutton|acpisleepbutton"
# check arguments
if [ $# -gt 1 ]; then
echo "Syntax error: Unkown argument '$2'\nUsage: ${0##*/} [ $args ]"
exit 1
fi
if [ -n "$1" ]; then
if [ -z $(echo $args | grep -o -w $1) ]; then
echo "Syntax error: Invalid parameter '$1'\nUsage: ${0##*/} [ $args ]"
exit 1
fi
fi
for vm in $(VBoxManage list runningvms | grep -o '".*"'); do
# delete first char
cmd="VBoxManage controlvm ${vm#?}"
# delete last char, and use parameter $1 if not empty
cmd="${cmd%?} ${1:-$act}"
echo "$cmd"
# excute command
$cmd
done
exit 0
本文介绍了一个用于批量控制VirtualBox中正在运行的虚拟机的Shell脚本。该脚本能够遍历当前运行中的所有虚拟机,并允许用户选择暂停、继续、重置、关闭电源、保存状态或使用ACPI按钮来控制虚拟机。
1224

被折叠的 条评论
为什么被折叠?



