Upload and Run a Script on a Guest Operating System
You can create a directory, create files, copy a script, and run the script on a
guest operating system.
Before you perform operations on the guest operating system, you must prepare the
environment. You must create the
Process.CreateSpec
for initiating
processes in the guest and create the Transfer.CreateSpec
for the
file transfer to or from the guest. The content of the optional
FileAttributeCreateSpec
associated with the
Transfer.CreateSpec
establishes the direction of the transfer
and controls guest operating system specific file attributes. You must set up
equivalent _download
and _upload
functions for
URL management of the file transfer to or from the guest. You can also create an
argument parser for standard inputs, such as server, user name, and password, and
you can add custom input arguments.- Find the virtual machine on which the guest operating system runs, verify that VMware Tools is running, and provide credentials.
- Create a temporary directory from which to run the script and capture any output.
- Create temporary files forstdoutandstderr.
- Copy the script that you want to run.
- Start the script and capturestdoutandstderrin the temporary files that you created earlier.
- Create a loop to handle processes that run longer.
- Create a download URL and copy the results.
- Clean up the temporary files and directories on the guest operating system.