- 论坛徽章:
- 0
|
有两台设备,需要先登入其中一台设备后再次ssh到另一台设备进行操作一些命令,编写后发现无法自动退出跳板的这个设备,请教写的哪里有问题?
import pexpect
jip = '192.168.100.63'
jsshport = '22'
jusername = 'test1'
jpassword = '123456789'
ip = '192.168.100.62'
sshport = '22'
username = 'test1'
password = '098765432'
jchild = pexpect.spawn ('ssh -p %s %s@%s' %(jsshport,jusername,jip))
jchild.expect ('assword: ')
jchild.sendline (jpassword)
#jchild.expect (['$','>','#'])
#jchild.sendline ('df -k')
jchild.expect (['$','>','#'])
jchild.sendline ('ssh -p %s %s@%s' %(sshport,username,ip))
jchild.expect ('assword: ')
jchild.sendline (password)
jchild.expect (['$','>','#'])
jchild.sendline ('df -h')
jchild.sendline ('exit')
#jchild.read()
#jchild.sendline ('exit')
#jchild.sendline ('exit')
#jchild.expect (['$','>','#'])
#jchild.sendline ('df')
jchild.interact ()
jchild.close()
#jchild.interact ('exit')
以上命令执行后 ,只能退出第二次ssh,第一次的ssh 无法正常退出,求教该如何写退出
谢谢了 |
|