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:
- $vmhost = Get-VMHost xxxxxxxxxxxxxxxxxx
- # Login credentials to SSH each host. It will convert the string from secure to plain text for plink
- $user = Read-Host "ESXi Host SSH User"
- $rootpword = Read-Host "ESXi Host SSH Password" -AsSecureString
- $rootbstr = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($rootpword)
- $rootpword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($rootbstr)
- # The "echo y" command automatically accepts the key for plink.
- echo y | C:\Users\xxxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword exit | Out-Null
- #execute patching
- C:\Users\xxxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch "chmod +x /tmp/CP035395.vmexe"
- 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"
- sleep -Seconds 60
- $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.
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
Hello Luc, yes they do work. I don't want to do extra manual work by ssh to each host... :smileyconfused:
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
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.
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
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...
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
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...
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
yes, I did. In fact from ssh I can patch the hosts successfully.
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
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:
Unfortunately I don't have a HP box to try it out
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks anyway for your time!
Hello!
Can you try this:
Create a cmds.txt with this content (without the "----" of course ):
-------------------------------------------------
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
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!