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. When I run this after I execute ssh
command program gets frozen and does not allow to execute commands into final remote server. In this case let's say I want to run ifconfig
on final server 'host.name'.
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()