Git Product home page Git Product logo

pynet's Introduction

Installation and Usage Tutorial for Multi-Server Python Script Execution

Requirements

Python 3.x
paramiko library (can be installed using pip install paramiko)
Installation

Clone the repository or download the following two python files:
main_server.py: This script should be run on your main computer. It contains a list of servers that you want to connect to and the script you want to run on those servers.
remote_server.py: This script should be run on each server that you want to connect to. It connects to the main server and waits for commands to execute.
Replace the servers list in main_server.py with a list of dictionaries containing the hostname, username, and password for each server you want to connect to. Also, replace the path to the script you want to run on the servers with the correct path.
On each server, replace the hostname, username, and password in remote_server.py with the correct values for your main server.
Usage

On your main computer, run the command python main_server.py to connect to each server in the list and run the specified script. The script will print the output and also the number of connected servers at the end.
On each server, run the command python remote_server.py to connect to the main server and listen for commands. The script will print the number of connected servers at the time of connecting and exiting.
On your main computer, you can now use the run_script function to run commands on multiple servers at once. You can also use the stdin, stdout, stderr = client.exec_command('read command') to read command from the main server and execute them on the connected servers.
To stop the script on the servers, you can use the command exit on the main server. This will cause the script to exit on each connected server, and the counter variable will decrement.
Note: The above example is just one way to do this, and there are many other libraries and tools that can be used to achieve similar results. Also, this is a basic example and you may want to add error handling and other features depending on your use case.

Please ensure that the script is run on the machines with proper permissions and also the remote machines should be configured to accept the ssh connection from the main machine.

pynet's People

Contributors

darkside-devops avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.