Did you try running the command in the background with something like this
'/sbin/services.sh restart &'
The plink command should return immediatly in this caseBlog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
Unfortunately, running it in the background only returns the exit code earlier (Server sent command exit status 0), as soon as the command is executed. But this doesn't actually change the result - it still runs through but fails to disconnect when completed.
Is anyone able to replicate this? I've done this on multiple systems, so I don't think this is something specific to my environment.
Thanks for the help.
Found a solution:
$command = "VAR=`$(pidof -s sshd) && /sbin/services.sh restart && kill `$VAR"
- Grabs the latest/newest ssh connection PID (your own) and stores in VAR
- NOTE: It's conceivable that there's a very small (fraction of a second) window where someone else *MAY* be able to log in after you do, but before the pidof command runs, just be aware
- Run service restart command
- Kill your own ssh connection PID to return control back to powershell script
This does what I needed it to. Hope this approach helps someone else.
Top notch Tocano!!! I was fighting with this exact issue when trying to running "/etc/init.d/hostd restart" with plink. Problem solved!!! Many thanks!!!!
Is it possible for you to post the script in its entirety? I find myself needing to set the syslog server and then restart the management agents for multiple hosts (over 100). Please advise as this script will greatly help my and my colleagues.
very useful as trying to batch up service management restarts with plink to work around this http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2109735
when I use the method above I end up killing the entire script "FATEL ERROR: server unexpectedly closed network connection" so it will not continue to the next item in the list