重启了一批节点,需要查看节点重启后的状态;
发现原来写简单的python还是不够用;于是又加了:
- def load_pwd(fp):
- fd = open(fp, "r")
- for el in fd:
- el.strip()
- ap = el.split()
- if len(ap) != 3:
- continue
- env.passwords["root@%s.xxxx"%(ap[0])] = ap[2]
- load_pwd('***')
- env.roledefs = {
- 'rc': ['xxx', 'oooo']
- }
- @roles('rc')
- def host_type():
- run('uname -s')
- with cd('/usr/local/xxx'):
- ret = run('ls -l')
- print "====================="
- print ret.succeeded,ret.return_code
- print ret
- print "====================="
- def ec(cmd):
- print(red("\n---------------start shell-------------------------------- |%s|\n"%(env.host)))
- run(cmd)
- print(green("---------------end shell---------------------------------- |%s|\n\n"%(env.host)))
- def ef(shell_file):
- shell = ""
- try:
- fd = open(shell_file, "r")
- shell = fd.read()
- except:
- print "cant open file"
- exit()
- ec(shell)
改动优化:
1,加入了自动加载 passwords;
2,在上一次的尝试加入了 role 的概念,这样更方便系统维护
3,可以直接在命令行中输入命令,这样对于一些简单的操作就不需要再去写 shell 脚本了;非常方便;
使用:
fab ec:"ps -ef | grep /usr/local/xxx | grep -v grep" -R rc -f a.py
阅读(1183) | 评论(0) | 转发(0) |