def sshcmd(cmd, host, password,):
''' runs single command on host using ssh
'''
p=expect.spawn("ssh " + host)
i0=p.expect([r'.+password:.*'])
if i0 == 0:
p.sendline(password)
i1=p.expect([r'Sorry.+', r'.*'])
if i1==0:
print('Wrongs password')
return 1
else:
print('inside')
p.sendline(cmd)
else:
print('Not expected')
评论列表
文章目录