小程序
时间:2011-05-24
来源:互联网
- """
- 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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28