1

I'm new to Python and i'm looking to run multiple parallel ssh connections and commands to the devices. I'm using pssh link for it. Issue is the device returns some big header after the connection like 20-30 lines. When i use the below code what is printed out is the result of the command but at the top there's also the big header that is printed after the login.

hosts = ['XX.XXX.XX.XXX']

client = ParallelSSHClient(hosts, user='XXXX', password='XXXXX')
output = client.run_command('command')

for host in output:
    for line in output[host]['stdout']:
        print line

Anyway i can get JUST the command output ?

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
LefterisL
  • 1,132
  • 3
  • 17
  • 37

2 Answers2

0

Not sure I understand what you mean. I'm using pssh as well, and seems like I'm using the same method as you are in order to print my command's output, see below:

client = pssh.ParallelSSHClient(nodes, pool_size=args.batch, timeout=10, num_retries=1)
output = client.run_command(command, sudo=True)
    for node in output:
        for line in output[node]['stdout']:
            print '[{0}]  {1}'.format(node, line)

Could you elaborate a bit more? Maybe provide an example of a command you run and the output you get?

Moshe Vayner
  • 738
  • 1
  • 8
  • 23
  • I had to actually drop ParallelSSH and move to paramiko and threading. The device was outputting an stdout on login. I also had to make a couple of changes to the SSHClient source code since the device doesn't have bash so i thought i'd be better of to drop it. I'm still having a couple of performance issues if you'd like to go over on chat. – LefterisL Jan 13 '16 at 10:03
  • If the device in question is outputting to stdout on login you will see that output in any SSH client you use. Standard output is standard output. Looking at the change log, bash is no longer required for parallel-ssh as of last year, might want to see if it resolves your performance issues. Hint - threads do not perform well for parallel network connections. – danny Jul 06 '17 at 14:49
0

checkout pssh.
This tool uses multi-threads and performs quickly.
you can read more about it here.

Gilad Sharaby
  • 910
  • 9
  • 12