Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #v1.0 - to supply password and login
  2. #shamlessly stolen form the web
  3. import sys
  4. import pexpect
  5.  
  6. user = 'user'
  7. password = 'password'
  8. host = 'host1.us.com'
  9. command = 'hostname ; echo $?'
  10. def dossh(user, password, host, command):
  11. child = pexpect.spawn('ssh %s@%s %s' % (user,host,command),logfile=sys.stdout,timeout=None)
  12. prompt = child.expect(['password:', r"yes/no",pexpect.EOF])
  13. if prompt == 0:
  14. child.sendline(password)
  15. elif prompt == 1:
  16. child.sendline("yes")
  17. child.expect("password:", timeout=30)
  18. child.sendline(password)
  19. data = child.read()
  20. print data
  21. child.close()
  22.  
  23. dossh(user, password, host, command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement