Guest User

Untitled

a guest
Feb 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. """Usage: ./backup.py login@host
  2. """
  3.  
  4. import sys
  5. import pexpect
  6. import getpass
  7.  
  8. child = pexpect.spawn('ssh ' + sys.argv[1])
  9. while True:
  10. match = child.expect(['password:', '\(.*\) >'])
  11. if match == 0:
  12. password = getpass.getpass('Password: ')
  13. child.sendline(password)
  14. else:
  15. break
  16. child.sendline('enable')
  17. child.expect('Password:')
  18. child.sendline(password)
  19. child.expect('#')
  20. child.sendline('show startup-config')
  21.  
  22. while True:
  23. match = child.expect(['^[^\r\n]*\r?\n',
  24. '^--More-- or \(q\)uit',
  25. '\r \r',
  26. '^\(.*\) #'])
  27. line = child.match.group(0).decode('utf-8').strip()
  28. if match == 0:
  29. print(line)
  30. elif match == 1:
  31. child.send(' ')
  32. elif match == 2:
  33. pass
  34. else:
  35. break
Add Comment
Please, Sign In to add comment