Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 995055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:39:44+00:00 2026-05-16T06:39:44+00:00

The code below runs grep in one machine through SSH and prints the results:

  • 0

The code below runs grep in one machine through SSH and prints the results:

import sys, os, string
import paramiko

cmd = "grep -h 'king' /opt/data/horror_20100810*"

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.10.3.10', username='xy', password='xy')
stdin, stdout, stderr = ssh.exec_command(cmd)
stdin.write('xy\n')
stdin.flush()

print stdout.readlines()

How can I grep five machines all at once (so that I don’t have major delay), than put all that in five variables and print them all out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:39:45+00:00Added an answer on May 16, 2026 at 6:39 am

    You’ll need to put the calls into separate threads (or processes, but that would be overkill) which in turn requires the code to be in a function (which is a good idea anyway: don’t have substantial code at a module’s top level).

    For example:

    import sys, os, string, threading
    import paramiko
    
    cmd = "grep -h 'king' /opt/data/horror_20100810*"
    
    outlock = threading.Lock()
    
    def workon(host):
    
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(host, username='xy', password='xy')
        stdin, stdout, stderr = ssh.exec_command(cmd)
        stdin.write('xy\n')
        stdin.flush()
    
        with outlock:
            print stdout.readlines()
    
    def main():
        hosts = ['10.10.3.10', '10.10.4.12', '10.10.2.15', ] # etc
        threads = []
        for h in hosts:
            t = threading.Thread(target=workon, args=(h,))
            t.start()
            threads.append(t)
        for t in threads:
            t.join()
    
    main()
    

    If you had many more than five hosts, I would recommend using instead a “thread pool” architecture and a queue of work units. But, for just five, it’s simpler to stick to the “dedicated thread” model (especially since there is no thread pool in the standard library, so you’d need a third party package like threadpool… or a lot of subtle custom code of your own of course;-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure why you want to do 1), but… May 16, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer a simple hack would be to say something like: var… May 16, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer This is done with satellite assemblies. You can see what… May 16, 2026 at 9:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to extend one of my WebApps using IronPython, unfortunately the code below
The test code below leads to a null pointer deference bug on a String
I have a question in regards to the code below. The code I have
the code below are all height=100%, it works fine in chrome but it displayes
I've got this code below, where I spawn several threads, normally about 7, and
I'm using the code below to to write to a file but at the
I expected the code below to print Hello, world! every 5 seconds, but what
Please see the code below: #include <windows.h> int main(int argc, char* argv[]) { HANDLE
if you try my code below you can see that the background color is
I've got a function that runs a user generated Regex. However, if the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.