Guest User

Untitled

a guest
Apr 6th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import pexpect
  2. import sys
  3. import os
  4. import getpass
  5.  
  6. hostname = "router-2"
  7. username = raw_input('Enter Your username: ')
  8. password = getpass.getpass('Password:')
  9.  
  10. fout = file('agglog.txt','w')
  11.  
  12. child = pexpect.spawn('ssh %s@%s' % (username, hostname))
  13. child.logfile_read = fout
  14. child.expect('Password:')
  15. child.sendline(password)
  16. child.expect('>')
  17. child.sendline('enable')
  18. child.expect('Password:')
  19. child.sendline(password)
  20. child.expect('#')
  21. child.sendline('show processes cpu history')
  22. i = child.expect(["--More--","#"])
  23. if i==0:
  24. child.sendline(' ') ###PROBLEM IS HERE
  25. else:
  26. child.sendline('show processes cpu | i Core 0|Core 1')
  27. child.expect('#')
  28. child.sendline('logout')
  29.  
  30. router-2#show processes cpu history
  31.  
  32. History information for system:
  33.  
  34.  
  35. 111112222222222111111111122222111111111122222111111111111111
  36. 777770000000000999998888833333888889999900000999998888899999
  37. 100
  38. 90
  39. 80
  40. 70
  41. 60
  42. 50
  43. 40
  44. 30
  45. 20 ************************************************************
  46. 10 ************************************************************
  47. 0....5....1....1....2....2....3....3....4....4....5....5....
  48. 0 5 0 5 0 5 0 5 0 5
  49. CPU% per second (last 60 seconds)
  50.  
  51.  
  52. 222222222222222222221222222222222222222222222222222222222222
  53. 342000300104111121019410422602031010060202210143001042120601
  54. --More--
  55.  
  56. while count < 10:
  57. output = child.readline()
  58. if '--More--' in output:
  59. child.sendline(' ')
  60. elif '#' in output:
  61. child.sendline('logout')
  62. count +=1
  63. time.sleep(1)
Add Comment
Please, Sign In to add comment