2

I have a (maybe) unusual situation. I need to run VMware CLI commands in a Windows box, but via the cygwin CLI inside a shell script. I can NOT change this for now, so any suggestions to "why not do this instead" may be futile, although appreciated. Here's a sample script.

#!/bin/bash
# Paths for vmware-cmd.pl file to run vmware commands from vsphere cli
_vcli_dir="/cygdrive/c/Program Files (x86)/VMware/VMware vSphere CLI"
_vcli_bin="$_vcli_dir/bin"
_vcli_perl="$_vcli_dir/Perl"
_vcli_perl_bin="$_vcli_perl/bin"
_vcli_perl_lib="$_vcli_perl/lib"
_vcli_perl_vlib="$_vcli_perl_lib/VMware"
_vcmd=vmware-cmd.pl

export _orig_path=$PATH
# Add above directories to path variable
export PATH=$PATH:$_vcli_dir:$_vcli_bin:$_vcli_perl:$_vcli_perl_bin:$_vcli_perl_lib:$_vcli_perl_vlib
echo $PATH

$_vcmd /?

export PATH=$_orig_path
echo $PATH

When I run the above script, I get

Can't locate VMware/VIRuntime.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int /usr/lib/perl5/site_perl/5.14 /usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int /usr/lib/perl5/vendor_perl/5.14 /usr/lib/perl5/5.14/i686-cygwin-threads-64int /usr/lib/perl5/5.14 /usr/lib/perl5/site_perl/5.10 /usr/lib/perl5/vendor_perl/5.10 /usr/lib/perl5/site_perl/5.8 .) at /cygdrive/c/Program Files (x86)/VMware/VMware vSphere CLI/bin/vmware-cmd.pl line 8. BEGIN failed--compilation aborted at /cygdrive/c/Program Files (x86)/VMware/VMware vSphere CLI/bin/vmware-cmd.pl line 8.

I can run the same vmware-cmd.pl script from a DOS command prompt

c:> vmware-cm.pl

So I now my installation is correct.

Any clues please?

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
Chris F
  • 14,337
  • 30
  • 94
  • 192

3 Answers3

0

This post gave me the idea to fix it. But now I get a core dump. How is Perl's @INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?)

The added line is the second export PERL5LIB line.

#!/bin/bash
# Path for vmware-cmd.pl file to run vmware commands from vsphere cli
_vcli_dir="/cygdrive/c/Program Files (x86)/VMware/VMware vSphere CLI"
_vcli_bin="$_vcli_dir/bin"
_vcli_perl="$_vcli_dir/Perl"
_vcli_perl_bin="$_vcli_perl/bin"
_vcli_perl_lib="$_vcli_perl/lib"
_vcli_perl_vlib="$_vcli_perl_lib/VMware"
_vcmd=vmware-cmd.pl

export _orig_path=$PATH
# Add above directories to path variable
export PATH=$PATH:$_vcli_dir:$_vcli_bin:$_vcli_perl:$_vcli_perl_bin:$_vcli_perl_lib:$_vcli_perl_vlib
export PERL5LIB=$_vcli_dir:$_vcli_bin:$_vcli_perl:$_vcli_perl_bin:$_vcli_perl_lib:$_vcli_perl_vlib
echo $PATH

$_vcmd /?

export PATH=$_orig_path
echo $PATH
Community
  • 1
  • 1
Chris F
  • 14,337
  • 30
  • 94
  • 192
0

I solved by going through my elbow to get to my a**, as the saying goes.

What I did was
- Install vmware cli on my Windows box to the default directory
- Added environment variables for the VMware main directory, the bin directory, the Perl directory and the Perl/bin directory
- Added these environment variables to my PATH variable.

Then I created a vmware-cli.bat file that takes parameters and concatenates them into a vmware-cli command with the correct values. For example, I call this to list the VMs in the server

cygwin:> ./vmware-cli.bat vmware-cmd.pl --server MyServer --username User --password PW -l

Inside the batch file I essentailly do

REM Get first parm as the command, and then concatenate the rest of the parms
set VCLI_CMD=%1
shift
:LOOP
if %1x==x goto :EXECUTE
set VCLI_CMD=%VCLI_CMD% %1
shift
goto LOOP:

:EXECUTE
%VCLI_CMD%
Chris F
  • 14,337
  • 30
  • 94
  • 192
0

This is an alternative to the previous posted that will allow you to keep it in the same shell script

VIMCMD="/cygdrive/C/Program Files (x86)/VMware/VMware vSphere CLI/bin/vmware-cmd.pl"
VIMCMD_DOS=$(cygpath -d "$VIMCMD")
DOS_VIMCMD="cmd /c $VIMCMD_DOS"

Then you can run:

$ $DOS_VIMCMD --version
vSphere SDK for Perl version: 6.0.0
Script 'vmware-cmd.pl' version: 6.0.0
kraught
  • 67
  • 4