/usr/share/doc/ruby-rbvmomi/examples/screenshot.rb is in ruby-rbvmomi 1.8.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # Based on takeVMScreenshot.pl by William Lam
require 'trollop'
require 'rbvmomi'
require 'rbvmomi/trollop'
VIM = RbVmomi::VIM
opts = Trollop.options do
banner <<-EOS
Take a screenshot.
Usage:
screenshot.rb [options] vm filename
A PNG image will be saved to the given filename.
VIM connection options:
EOS
rbvmomi_connection_opts
text <<-EOS
VM location options:
EOS
rbvmomi_datacenter_opt
text <<-EOS
Other options:
EOS
end
Trollop.die("must specify host") unless opts[:host]
vm_name = ARGV[0] or abort("must specify VM name")
output_path = ARGV[1] or abort("must specify output filename")
vim = VIM.connect opts
dc = vim.serviceInstance.find_datacenter(opts[:datacenter])
vm = dc.find_vm vm_name
abort "VM must be running" unless vm.runtime.powerState == 'poweredOn'
remote_path = vm.CreateScreenshot_Task.wait_for_completion
remote_path =~ /^(\/vmfs\/volumes\/[^\/]+)\// or fail
datastore_prefix = $1
datastore_path = $'
datastore = vm.datastore.find { |ds| ds.info.url == datastore_prefix }
datastore.download datastore_path, output_path
|