Multithread Remote SSH with Python

De Wiki Clusterlab.com.br
Revisão de 18h07min de 25 de janeiro de 2022 por Damato (discussão | contribs) (→‎run.py)
Ir para navegação Ir para pesquisar

run.py

#!/usr/bin/env python
from src.activeInventory import ActiveInventory
from src.configs import Config
from src.argmenu import ArgMenu
import time
class main:
    def remoteExecution():
        argsmenu = ArgMenu()
        args = argsmenu.get_args()
        activeInventory = ActiveInventory(args.outdir)
        credfile = Config(args.cred)
        credentials = credfile.get_data("credentials")
        with open(args.servers, "r") as servers:
            control = 1
            count = 0
            for server in servers:
                count = count + 1
                if control == 0:
                    control = 1
                    continue
                for credential in credentials:
                    # time.sleep(1)
                    if control == 0:
                        break
                    if activeInventory.run_remote_command(command=args.cmd,
                                                          username=credential["username"],
                                                          password=credential["password"],
                                                          prefix=args.prefix,
                                                          server=server.replace("\n", "")) == 0:
                        control = 0

if __name__ == "__main__":
    main.remoteExecution()

runp.py

src/activeinventory.py

src/argmenu.py

src/configs.py