I have a Powershell script that will automatically SSH to a Linux host (ESXI Server running Busybox) and will run a singular command (./my_script.sh), which captures some network traffic on the ESXI server. However, this script waits for user input (CTRL + C) to exit the script.

I have tried using the Posh-SSH module (Invoke-SSHCommand -SSHSession $session -Command $command) syntax as well as the Plink module (plink -batch *servername* -pw *userPassword* *command*) but the commands always execute and return me back to the shell, they never wait for user interaction.

Of course, if I run it directly on the ESXI server the script will wait for the CTRL + C command to terminate.

Does anybody know of a workaround for this?

1

There are 1 best solutions below

3
On

On option is the timeout command which shuold be present on , to set a runtime limit for whatever command you are running. For example, if you needed tcpdump to capture packets for 20 seconds you could run:

timeout 20 tcpdump

You can also specify a specific signal to send to the process with the --signal flag, if the command you are using has inconsistent behavior across different signals (view a list of signals wit kill -l`):

timeout --signal INT 20 tcpdump