小程序
- """
- Usage:bmcdebuglog.py -smmip smmip -smmpassword smmpassword -slot slot
-
- Options:
- -smmip smmip
- -smmpassword smmpassword
- -slot slot
- """
-
- import pexpect
- import os, sys, commands
- import time
- from pexpect import *
-
-
- opts = sys.argv[1:]
-
- if not len(opts) == 6:
- print __doc__,
- sys.exit(1)
-
- user = "root"
- smmip = opts[1]
- smmpwd = opts[3]
- slot = opts[5]
-
- def mkpwd(str):
- print str
- li = str.split(' ')
- times = li[-1].split(':')
- passwd = 'd pa'+times[1]+times[0]
- return passwd
-
- def telnet(smmip,passwd):
- child=pexpect.spawn('telnet %s 1101'%smmip,timeout=5)
- index = child.expect([".*user",pexpect.TIMEOUT,"Reach Max Connect Count"])
- if index == 1:
- time.sleep(3)
- child.sendline('telnet %s 1101'%smmip)
- index = child.expect([".*user",pexpect.TIMEOUT])
- if index == 1:
- print child.before
- print 'cant telnet to %s '%smmip
- sys.exit(1)
- if index == 2:
- print "Reach Max Connect Count!Connection closed by foreign host"
- sys.exit(1)
- child.sendline("root\r")
- child.expect(".*ord")
- child.sendline('%s\r'%passwd)
- index = child.expect([".*choice",".*user",pexpect.TIMEOUT])
- if index == 1:
- time.sleep(1)
- child.sendline("root\r")
- child.expect(".*ord")
- child.sendline('%s\r'%passwd)
- index = child.expect([".*choice",".*user",pexpect.TIMEOUT])
- if not index == 0:
- print 'smm password %s is wrong!'%passwd
- sys.exit(1)
- if index == 2:
- print "login failed:"
- print child.before
- sys.exit(1)
- return child
-
-
- try:
- child = telnet(smmip,smmpwd)
- child.sendline('%s\r'%slot)
- index = child.expect(["COM","the command times out",pexpect.TIMEOUT])
- if index == 1:
- print "the blade is not present!"
- sys.exit(1)
- if index == 2:
- print "choose slot failed : "
- print child.before
- sys.exit(1)
- child.sendline("2\r")
- index = child.expect(["KVM","root>","debug>"])
- if index == 0:
- print "The blade is performing KVM connection!"
- sys.exit(1)
- time.sleep(1)
- child.sendline("\n")
- index = child.expect(["root>","debug>"])
- if index == 1:
- print '12'
-
- elif index == 0:
- child.sendline("debug\r")
- child.expect('Current.*')
- print child.before
- debugpwd = mkpwd(child.after)
- print debugpwd
- child.sendline(debugpwd+"\r")
- child.expect("debug>")
- child.sendline("io")
- child.expect([pexpect.EOF,pexpect.TIMEOUT])
- print child.before
- print 'sen s'
- child.sendline('sen s')
- child.expect([pexpect.EOF,pexpect.TIMEOUT])
- print child.before
- print 'd 20000f'
- child.sendline('d 20000f')
- child.expect([pexpect.EOF,pexpect.TIMEOUT])
- print child.before
- child.close()
- sys.exit(0)
- except Exception, e:
- print e
作者: chinaboywg 发布时间: 2011-05-24
大哥,给点注释,说明什么的啊,我等新手看起来很吃力
作者: e2fsck 发布时间: 2011-05-25