简体   繁体   English

使用 Paramiko 从远程服务器执行命令到另一个远程服务器

[英]Executing command from remote server into another remote server using Paramiko

I am trying to connect to a specific central server that has configured passwordless connection to all other servers, the server I am currently on has no access to the ones I want to run commands.我正在尝试连接到已配置与所有其他服务器的无密码连接的特定中央服务器,我当前所在的服务器无法访问我想要运行命令的服务器。 So I am trying to connect to central server and from there do ssh into other servers I need to run commands.所以我试图连接到中央服务器,然后从那里做ssh到我需要运行命令的其他服务器。 When I run this after I execute ssh command program gets frozen and does not allow to execute commands into final remote server.当我在执行ssh命令后运行它时,程序被冻结并且不允许将命令执行到最终的远程服务器中。 In this case let's say I want to run ifconfig on final server 'host.name'.在这种情况下,假设我想在最终服务器“host.name”上运行ifconfig

def get_host_info_linux(self,host,db_engine):
    #Create ssh client from paramiko library
    client = paramiko.SSHClient()

    try:
        # Connect to remote host
        #logger.info(username_pass)
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(hostname='tunel host name', username=f'{db_engine}')
        #this command is to do ssh into the server I want to execute commands
        ssh_cmd = f'ssh {host.name}'

        ssh_std = client.exec_command(ssh_cmd)
        if (ssh_std[2].readlines() == []):+

            logger.debug(ssh_std[1].readlines()[0])

        else:
            logger.error(ssh_std[2].readlines())

      client.exe_command('ifconfig')

    except Exception as e:
        logging.error(e)
    finally:
        client.close()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果使用 Paramiko 在远程服务器上启动的命令没有响应,则在一定时间后杀死远程 session - Kill remote session after certain time, if no response from command launched on remote server using Paramiko 使用paramiko在远程计算机上不执行cqlsh命令 - Using paramiko not executing cqlsh command on remote machine 使用Python中的Paramiko从远程命令列出的SFTP服务器下载文件 - Downloading files from SFTP server listed by remote command with Paramiko in Python SSH Paramiko命令未更改远程服务器中的目录 - SSH Paramiko command is not changing the directory in remote server 使用 Paramiko 在远程机器上执行命令无效 - Executing command on remote machine using Paramiko has no effect 使用解耦,冗余和异步在远程服务器上执行命令 - Executing a command on a remote server with decoupling, redundancy, and asynchronous 使用Python Paramiko在后台运行远程SSH服务器的过程 - Running process of remote SSH server in the background using Python Paramiko paramiko - 如何从 sudoer 实例连接远程服务器 - paramiko - How to connect a remote server from sudoer instance 是否可以结合使用 Paramiko 和 Dask 的 read_csv() 方法从远程服务器读取 .csv? - Is it possible to read a .csv from a remote server, using Paramiko and Dask's read_csv() method in conjunction? 如何使用 python paramiko 模块从远程服务器获取服务详细信息 - How to get the services details using the python paramiko module from the remote server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM