Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to execute multiple commands on the same hosts #114

Open
ghost opened this issue Apr 3, 2018 · 1 comment
Open

Ability to execute multiple commands on the same hosts #114

ghost opened this issue Apr 3, 2018 · 1 comment

Comments

@ghost
Copy link

@ghost ghost commented Apr 3, 2018

Feature Request
I've read through examples and the current ParallelSSH can

  • execute a command with different arguments
  • execute different commands on different hosts

What's missing is the ability to execute multiple commands on each host and perhaps group the output to each host.

Example:

hosts = ['server1', 'server2', 'server3']
cmds = ['date', 'uptime', 'pwd']
output = client.run_command (cmds)

Current Work-Around State:

client = ParallelSSHClient (hosts, user = username, password = password)
data = [client.run_command(cmd) for cmd in cmds]
for entry in data:
    for host, host_output in entry.items ():
        print (host)
        for line in host_output.stdout:
            print (line)

Actual Output:

server1
Tue Apr  3 00:03:11 UTC 2018
server2
Tue Apr  3 00:03:11 UTC 2018
server3
Tue Apr  3 00:03:11 UTC 2018
server1
00:03:12 up 7 days, 15:27,  1 user,  load average: 0.00, 0.00, 0.00
server2
00:03:12 up 2 days, 15:27,  1 user,  load average: 0.00, 0.00, 0.00
server3
00:03:12 up 9 days, 15:27,  1 user,  load average: 0.00, 0.00, 0.00
server1
/home/username
server2
/home/username
server3
/home/username

It's not the prettiest nor do I entertain the idea of 3 nested for-loops that defeated the purpose of parallel-SSH with each loop eating into the performance. If there's a better way to implement this, let me know or if it doesn't exist, please implement it.

Preferred Output:

server1
Tue Apr  3 00:03:11 UTC 2018
00:03:12 up 7 days, 15:27,  1 user,  load average: 0.00, 0.00, 0.00
/home/username

server2
Tue Apr  3 00:03:11 UTC 2018
00:03:12 up 2 days, 15:27,  1 user,  load average: 0.00, 0.00, 0.00
/home/username

server3
Tue Apr  3 00:03:11 UTC 2018
00:03:12 up 9 days, 15:27,  1 user,  load average: 0.00, 0.00, 0.00
/home/username
@pkittenis
Copy link
Member

@pkittenis pkittenis commented Apr 6, 2018

Hi there,

Thanks for the interest and feature request.

One option is, as shown above, to run individual commands separately. Performance wise there is not much overhead as all commands are executed asynchronously whether they were started together or one after the other.

That overhead is the same whether the starting of commands is done client side or by parallel-ssh itself.

The other option is to run multiple commands together per server, eg:

hosts = ['server1', 'server2', 'server3']
cmd = ';'.join(['date', 'uptime', 'pwd'])
output = client.run_command (cmd)

This gives the desired output. The three commands are however executed serially per host. How to run the commands also depends on the users' shell.

I think adding a convenience function for running multiple commands per host in parallel and simplifying output gathering would be useful - it's not the first time it has been asked. The output generators can be chained together to give combined output.

However, it is worth pointing out that this will not yield any performance benefit over a client-side function that does the same thing.

@pkittenis pkittenis added this to the 2.0.0 milestone Apr 6, 2018
@pkittenis pkittenis removed this from the 2.0.0 milestone Aug 13, 2020
@pkittenis pkittenis added the PR wanted label Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.