Skip to content

Instantly share code, notes, and snippets.

@mmb
Created September 12, 2012 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmb/3704738 to your computer and use it in GitHub Desktop.
Save mmb/3704738 to your computer and use it in GitHub Desktop.
Scripting VM virtual consoles from the host.
# Writing to Linux virtual consoles to simulate user input:
s = "ls\n"
open('/dev/tty1','w') do |f|
s.each_char do { |c| f.ioctl(0x5412, c) }
end
# From the shell:
echo 7 | ruby -e "open('/dev/tty1', 'w') { |o| \$stdin.each_char { |c| o.ioctl(0x5412, c) } }"
# To the virtual console of a VM from the host:
echo -e "open('/dev/tty1', 'w') { |o| DATA.each_char { |c| o.ioctl(0x5412, c) } }\n__END__" > script.rb
echo 8 >> script.rb
"/Applications/VMware Fusion.app/Contents/Library/vmrun" -gu root -gp test CopyFileFromHostToGuest your.vmx script.rb /tmp/script.rb
"/Applications/VMware Fusion.app/Contents/Library/vmrun" -gu root -gp test runProgramInGuest your.vmx /usr/bin/ruby /tmp/script.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment