Page MenuHomePhabricator
Paste P6877

a simple VBoxManage wrapper
ActivePublic

Authored by dduvall on Mar 21 2018, 6:20 PM.
Tags
None
Referenced Files
F15949508: a simple VBoxManage wrapper
Mar 21 2018, 6:20 PM
Subscribers
None
#!/usr/bin/ruby
action, name = *ARGV
abort "usage: #{$PROGRAM_NAME} [start|stop|halt] vm" unless action && name
vm = `VBoxManage list vms`.each_line.map do |l|
l.split(' ').first.split('"')[1]
end.find do |vm|
name.casecmp(vm) == 0
end
abort "vm `#{name}' not found" unless vm
case action
when "start"
puts "Starting VM #{vm}..."
Process.detach Kernel.spawn("VBoxHeadless", "-s", vm)
when "stop"
puts "Stopping VM #{vm}..."
`VBoxManage controlvm #{vm} savestate`
when "halt"
puts "Halting VM #{vm}..."
`VBoxManage controlvm #{vm} acpipowerbutton`
end

Event Timeline

dduvall changed the title of this paste from untitled to a simple VBoxManage wrapper.
dduvall updated the paste's language from autodetect to autodetect.