Pyhon Parallel-Ssh Sending Commands In Loop In a Single Shell Does Not Work

101 views Asked by At

I have been trying to send a single command in a loop for a single client in a single shell because different commands need to go before the loop to get into a terminal using Parallel-ssh.

Code:

pclient = ParallelSSHClient(['ipaddress'], user="username", password='password')
shell = pclient.open_shell()
commands = ["echo 'Hello, world!' > example.txt"]
pclient.run_shell_commands(shell, commands)

for _ in range(20):
    pclient.run_shell_commands(shell, ["cat example.txt"])
    for sell in shell:
        for line in sell.stdout:
            print(line)

After every iteration, I expect it to print both of the commands' outputs.

However, the moment it prints out the last line in the first iteration it's not moving forward in the loop. there is not error message and the code does not continue

I tried using ParallelSSHclient as well as SSHClient, closing the shell, getting the exit code and running each command individually.

I don't understand why it won't continue the loop and print the next output ...

0

There are 0 answers