VMware Fusion 2 and other VMware products include a command line utility called "vmrun". On OS X, you'll find that at "/Library/Application Support/VMware Fusion". You can download a PDF that describes its use at http://www.vmw.com/ beta/fusion/vmrunCommand.pdf.
If you want a great guide to learning Fusion, consider Joe Kissel's Take Control of VMware Fusion 2, a $10.00 PDF E-book that will teach you everything you need to know.
You can use vmrun to start and stop virtual machines from the command line. You can suspend and reset machines also. That's all very simple:
vmrun start Ubuntu/Ubuntu.vmx vmrun suspend Ubuntu/Ubuntu.vmx vmrun start Ubuntu/Ubuntu.vmx vmrun stop Ubuntu/Ubuntu.vmx
What may be more interesting is that you can inspect the process list. You do need to install VMware tools first:
$ vmrun -gu apl -gp mypasswd listProcessesInGuest Ubuntu.vmx (long delay) Error: The VMware Tools are not running in the virtual machine: /Volumes/WD250/Ubuntu.vmwarevm/Ubuntu.vmx
Although VMware provides VMware Tools, Fusion can't actually install them - it simply mounts a virtual CD image and you do a manual install. For Ubuntu, that involves unpacking and compiling source, some of which failed when I tried it. However, most of the important things did compile and were able to be linked into the kernel so soon I could do:
$ vmrun -gu apl -gp mypasswd listProcessesInGuest Ubuntu.vmx Process list: 69 pid=1, owner=root, cmd=/sbin/init pid=914, owner=root, cmd=/sbin/udevd --daemon pid=2231, owner=root, cmd=/sbin/getty 38400 tty4 pid=2232, owner=root, cmd=/sbin/getty 38400 tty5 pid=2238, owner=root, cmd=/sbin/getty 38400 tty2 pid=2239, owner=root, cmd=/sbin/getty 38400 tty3 pid=2244, owner=root, cmd=/sbin/getty 38400 tty6 ..
You can do the same thing with a Windows VM.
I did have one other problem with the tools: it reset my X display to 1366x768 . That was impossible to read, so I did a Ctrl-Alt-F1 to get a login screen, edited /etc/X11/xorg.conf and did a "killall Xorg" to fix that.
There's more: you can create directories in a running Vm:
vmrun -gu apl -gp mypasswd createDirectoryInGuest ~/Desktop/Ubu*/Ubuntu.vmx /tmp/newdir
You can even run programs. That's not particularly exciting for Linux as you could do that several easier ways, but it could be interesting for Windows VM's.
Not that when you run programs, the output doesn't appear at your Mac. In the case of Linux, the output doesn't appear anywhere unless you have told the command to put its output somewhere. A script could redirect to /dev/tty1, an X11 app could use Display :0 and so on.
On Windows, the commands run in the VM console if you use the credentials of the logged in user.
I had a lot of trouble with running programs and scripts. I could easily run a script that I had created, say "/tmp/myscript":
date > /dev/tty1 date > /tmp/foo echo $1 >> /tmp/foo
That would run with
vmrun -gu apl -gp mypasswd runprogramInGuest ~/Desktop/Ubu*/Ubuntu.vmx /tmp/myscript args
If you were logged in on tty1 (ctrl-alt-F1) you'd see the output and of course would also find it in /tmp/foo.
However, I had problems running Perl scripts such as they show in examples. There doesn't appear to be any logging so it's very hard to figure out what might be wrong.. but it hardly matters as you can always just bundle up whatever you need in another script.
Vmrun makes it possible to automate tasks in virtual machines. I don't have any particular need for that right now, but it's easy to imagine cases where I would.
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar