Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Usage: ./backup.py login@host
- """
- import sys
- import pexpect
- import getpass
- child = pexpect.spawn('ssh ' + sys.argv[1])
- while True:
- match = child.expect(['password:', '\(.*\) >'])
- if match == 0:
- password = getpass.getpass('Password: ')
- child.sendline(password)
- else:
- break
- child.sendline('enable')
- child.expect('Password:')
- child.sendline(password)
- child.expect('#')
- child.sendline('show startup-config')
- while True:
- match = child.expect(['^[^\r\n]*\r?\n',
- '^--More-- or \(q\)uit',
- '\r \r',
- '^\(.*\) #'])
- line = child.match.group(0).decode('utf-8').strip()
- if match == 0:
- print(line)
- elif match == 1:
- child.send(' ')
- elif match == 2:
- pass
- else:
- break
Add Comment
Please, Sign In to add comment