6 Replies Latest reply on Oct 23, 2015 8:22 AM by beefy147

    Unable to return from plink command on host

    Tocano Enthusiast

      I have a PowerCLI script that, among other things, loops through a list of ESXi hosts (5.0) and executes command(s) on each using PuTTY\plink.exe. While this works 99% of the time, we've run into a couple of occurences (e.g. restarting management services) where it hangs, failing to return program control when the remote command completes. For example, using the following code:



      $command = "/sbin/services.sh restart"

      ($nextHost in $hostList) {     $userhost = $user + "@" + $nextHost

      echo "$(date -format s) Executing command '$command' on host $nextHost"
      $plinkPath -v -batch -pw $pw $userhost $command
          echo "$(date -format s) Command completed."

      echo "Sleeping for $delay seconds"
          sleep -Seconds $delay



      It will successfully connect and run the command, thus restarting services, but at the end, I get this:



      Running vmware-fdm restart

      Starting vmware-fdm:success


      Server sent command exit status 0

      Where it just sits, waiting for ... something. Since it doesn't close the connection, it doesn't return program control to the PowerShell script and it won't continue on to the next host.


      I've even tried running the command '/sbin/services.sh restart && exit' or && return 2' or even && ls' without luck. I've tested this on both multiple 2008 R2 and 2012 systems. You can probably easily replicate it (assuming PuTTY installed) by simply opening up a PowerShell console and executing:


      > & 'C:\Program Files (x86)\PuTTY\plink.exe' -v -batch -pw "[root password]" root@[FQDNesxihostname] '/sbin/services.sh restart'


      Contrast that behavior with something like:


      >  & 'C:\Program Files (x86)\PuTTY\plink.exe' -v -batch -pw "[root  password]" root@[FQDNesxihostname] 'ls'


      Any help on how to get this to close the connection and return program control would be appreciated.