Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pexpect
- import sys
- import os
- import getpass
- hostname = "router-2"
- username = raw_input('Enter Your username: ')
- password = getpass.getpass('Password:')
- fout = file('agglog.txt','w')
- child = pexpect.spawn('ssh %s@%s' % (username, hostname))
- child.logfile_read = fout
- child.expect('Password:')
- child.sendline(password)
- child.expect('>')
- child.sendline('enable')
- child.expect('Password:')
- child.sendline(password)
- child.expect('#')
- child.sendline('show processes cpu history')
- i = child.expect(["--More--","#"])
- if i==0:
- child.sendline(' ') ###PROBLEM IS HERE
- else:
- child.sendline('show processes cpu | i Core 0|Core 1')
- child.expect('#')
- child.sendline('logout')
- router-2#show processes cpu history
- History information for system:
- 111112222222222111111111122222111111111122222111111111111111
- 777770000000000999998888833333888889999900000999998888899999
- 100
- 90
- 80
- 70
- 60
- 50
- 40
- 30
- 20 ************************************************************
- 10 ************************************************************
- 0....5....1....1....2....2....3....3....4....4....5....5....
- 0 5 0 5 0 5 0 5 0 5
- CPU% per second (last 60 seconds)
- 222222222222222222221222222222222222222222222222222222222222
- 342000300104111121019410422602031010060202210143001042120601
- --More--
- while count < 10:
- output = child.readline()
- if '--More--' in output:
- child.sendline(' ')
- elif '#' in output:
- child.sendline('logout')
- count +=1
- time.sleep(1)
Add Comment
Please, Sign In to add comment