VMware Cloud Community
zenivox
Hot Shot
Hot Shot

vmexe HP files execution with PowerCLI

At the end I'm submitting a new thread as I saw that old thread was not moved to the top after the update.

I created a script to upload the file CPxxxx.vmexe successfully to all involved ESXi hosts. Then I'm running this but it produces no result:

  1. $vmhost = Get-VMHost xxxxxxxxxxxxxxxxxx 
  2.  
  3. # Login credentials to SSH each host. It will convert the string from secure to plain text for plink 
  4. $user = Read-Host "ESXi Host SSH User" 
  5. $rootpword = Read-Host "ESXi Host SSH Password" -AsSecureString 
  6. $rootbstr = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($rootpword) 
  7. $rootpword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($rootbstr) 
  8.  
  9. # The "echo y" command automatically accepts the key for plink. 
  10.   echo y | C:\Users\xxxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword exit | Out-Null 
  11.  
  12. #execute patching 
  13. C:\Users\xxxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch "chmod +x /tmp/CP035395.vmexe" 
  14. start-process "cmd.exe" "/c echo y | C:\Users\xxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch /tmp/CP035395.vmexe" 
  15.  
  16. sleep -Seconds 60 
  17.  
  18. $VMhost | Restart-VMHost -Confirm:$false | Out-Null

the host gets rebooted but patch is not applied. Is there a way to successfully execute these kind of files with PowerCLI? Executing those commands from within a ssh session works fine.

Reply
0 Kudos
16 Replies
LucD
Leadership
Leadership

If you run those plink.exe lines from a CMD box, do they work? Or do they come back with an error?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

Hello Luc, yes they do work. I don't want to do extra manual work by ssh to each host... :smileyconfused:

Reply
0 Kudos
LucD
Leadership
Leadership

Why is there a difference in the call to plink.exe in your script?

One is done via Start-Process, any particular reason why?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

for the simple reason that so I can get a visual confirmation of the execution. Just that. However I just got a confirmation that even the first line to change permission is not working. If I run it from PowerCLI then into a ssh session I'm not able to successfully run a simple ./CPXXXXX.vmexe --help command. It gives me Permission denied. If I run the chmod command from a ssh session all ok. I'm using root account in all tries.

Reply
0 Kudos
LucD
Leadership
Leadership

Do you have sudo activated on that Linux box?

if yes, could it be the definition in /etc/sudoers?

Can you check what you have running in your sessions (both ssh and plink.exe) by executing a 'ps'?
Is there a difference?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

no sudo activated on any host. they can be managed only by root account.

I can see the output of ps with both ssh and plink. Line by line when I get to:

C:\Users\xxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch "chmod +x /tmp/CP035395.vmexe"

I get:

chmod: /tmp/CP035395.vmexe: No such file or directory

and if I provide plink with a cd /tmp/ before the line above the result is the same. I'm lost...

Reply
0 Kudos
LucD
Leadership
Leadership

Did you already do a 'pwd' before the other commands?
Just to know where you get in.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

I cleared the environment from all attempts. Now it returns

/

and the chown works (I'm able to manipulate the file even in ssh). However I get the cmd window flashing but the file does not flash the system. I'm afraid that these type of files don't work well in this context... or maybe this file in particular...

Reply
0 Kudos
LucD
Leadership
Leadership

I had a closer look at that patch, did you also copy the other files over (CP035395.xml and CP035395.vmfile)?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

yes, I did. In fact from ssh I can patch the hosts successfully.

Reply
0 Kudos
LucD
Leadership
Leadership

It might be that this binary doesn't read the stdin as one would expect.
You do get a prompt when you start the binary in a ssh session?

Can you pipe (echo 'y' |) the answer ('y' I assume) to the binary in a ssh session?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

I do get a prompt in ssh, and when I pipe echo 'y' | before the line it proceeds correctly without prompting... I give up :smileyconfused:

Reply
0 Kudos
LucD
Leadership
Leadership

Unfortunately I don't have a HP box to try it out Smiley Sad


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

thanks anyway for your time!

Reply
0 Kudos
rwk1982
Enthusiast
Enthusiast

Hello!

Can you try this:

Create a cmds.txt with this content (without the "----" of course Smiley Wink):

-------------------------------------------------

cd /tmp

chmod a=rwx CP035395*

./CP035395.vmexe -h

-------------------------------------------------

And then this PS Script:

-------------------------------------------------

$esx_admin = "root"

$esx_pass = "password"

$esx_host = "ESXi IP/FQDN"

$exe_plink = "plink.exe"

$cmds_plink = "cmds.txt"

$cmd_arg = "/c echo n | $exe_plink -ssh $esx_host -l $esx_admin -pw $esx_pass -m $cmds_plink"

Start-Process "cmd" -ArgumentList $cmd_arg -Wait -RedirectStandardOutput 1juhu.log -RedirectStandardError 2err.log

----------------------------------------------

The last line in the "cmds.txt" only prints the help of the vmexe which you can see in the "1juhu.log" - something like: "OS Version found  [6.5.0]..."

In the 2err.log are all errors. In the case of "-h" there is always this line:

./hpsetup: [-h] | [-d[<file>]] | | [--source=<dir> | [-s] [-f] [-r] [-e] [-g]

If you like to flash change the last line in the cmds.txt from

./CP035395.vmexe -h

to

./CP035395.vmexe -s -r

-s = Silent, no User Interaction

-r = Reboot

Hope this helps.

Robert

Drink coffee.. Do stupid things faster with more energy...
Reply
0 Kudos
zenivox
Hot Shot
Hot Shot

many thanks! I moved to a different department and I can't try it out, however I'll keep the script.. you never know!! Cheers!

Reply
0 Kudos