0

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 ...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Note [mre] guidelines: A code sample should be something we _can actually run ourselves_ to see the problem and test proposed fixes -- being complete enough to run means things like importing the libraries you use, ensuring that if you refer to `self` you're part of a method, etc. Think about using commands like `echo A`, `echo B`, etc; and make sure the code is the shortest possible thing that can be run _without changes_ (other than maybe adjustments to a hostname list) to see the same problem you're asking about. – Charles Duffy Jan 04 '23 at 16:45
  • 1
    Also, be careful about your tags. libssh is a C library; it's irrelevant to Python code; and I don't see what this question has to do with packaging. – Charles Duffy Jan 04 '23 at 16:46

0 Answers0