0

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?

Obsidian
  • 3,719
  • 8
  • 17
  • 30
a_polo
  • 1
  • 4

1 Answers1

0

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
joshmeranda
  • 3,001
  • 2
  • 10
  • 24
  • Is the --signal done within the powershell script or the linux script? – a_polo Mar 22 '21 at 18:00
  • Linux, `--signal` is a flag on the timeout command: `timeout --signal INT 1 sleep 10` will send a SIGINT to the `sleep` process to kill it after 1 second. Updated answer to be more clear – joshmeranda Mar 22 '21 at 18:10
  • Thanks for the update, but I need the script to run indefinitely until I tell it to stop. And I would also need it to be done using plink or posh-ssh as I'm running the script on linux from a powershell script. – a_polo Mar 22 '21 at 18:28