I've seen several questions and answers related to this topic but I've been unable to grasp the howto.
What I'm able to do : connect to a remote computer using a Python script using Paramiko and return information, for instance, to ping a switch :
ssh = pk.SSHClient()
ssh.set_missing_host_key_policy(pk.AutoAddPolicy())
ssh.connect('{}'.format(IP), port=xxx, username='xxx',password='xxx')
stdin, stdout, stderr = \
ssh.exec_command('ping -n 1 xxx.xxx.x.x\n')
print('Ping switch: \n', stdout.readlines())
What I would like to do but don't know how to : connect once to the computer and then using SSH (paramiko.SSHClient()) again connect to another device (in this case a NAS) and 'exec_command', something like :
ssh = pk.SSHClient()
ssh.set_missing_host_key_policy(pk.AutoAddPolicy())
ssh.connect('{}'.format(IP), port=xxx, username='xxx',password='xxx') # connect to computer
ssh.connect('{}'.format(IP), port=xxx, username='xxx',password='xxx') #connect to NAS from computer
stdin, stdout, stderr = \
ssh.exec_command('shutdown\n, y\n') # send command to NAS
print('Ping switch: \n', stdout.readlines())
Is this possible, does anyone know a way?
Thank you in advance.