Chinaunix首页 | 论坛 | 博客
  • 博客访问: 81148
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 137
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-24 08:12
文章分类

全部博文(20)

文章存档

2016年(6)

2015年(14)

分类: 系统运维

2016-06-13 14:53:12

公司因为需要用到很多服务器定时任务,让我写了一个fabric的可视化控制页面。而在后台中,我实际上是跑了一个fab -f的脚本命令,具体如下:
fab --hide running,status -f cmd.py excute:command='/usr/bin/rsync -avrtopg --password-file=/root/scripts/longyuan_pass.txt game@*.*.*.*::game/gamecenter_qpid_device_data  /data/webserver/bi.game.pps.tv/logs/',host="*.*.*.*"
运行这个脚本会出现这个错误
Traceback (most recent call last):
  File "/usr/lib64/python2.6/site-packages/fabric/main.py", line 703, in main
    commands_to_run = parse_arguments(arguments)
  File "/usr/lib64/python2.6/site-packages/fabric/main.py", line 539, in parse_arguments
    k, v = result

随后我去源码中看fabric源码在解析这条命令时的实现:
def parse_arguments(arguments):
    """
    Parse string list into list of tuples: command, args, kwargs, hosts, roles.


    See sites/docs/usage/fab.rst, section on "per-task arguments" for details.
    """
    cmds = []
    for cmd in arguments:
        args = []
        kwargs = {}
        hosts = []
        roles = []
        exclude_hosts = []
        if ':' in cmd:
            cmd, argstr = cmd.split(':', 1)
            for pair in _escape_split(',', argstr):
                result = _escape_split('=', pair)
                if len(result) > 1:
                    k, v = result
                    # Catch, interpret host/hosts/role/roles/exclude_hosts
                    # kwargs
                    if k in ['host', 'hosts', 'role', 'roles', 'exclude_hosts']:
                        if k == 'host':
                            hosts = [v.strip()]
                        elif k == 'hosts':
                            hosts = [x.strip() for x in v.split(';')]
                        elif k == 'role':
                            roles = [v.strip()]
                        elif k == 'roles':
                            roles = [x.strip() for x in v.split(';')]
                        elif k == 'exclude_hosts':
                            exclude_hosts = [x.strip() for x in v.split(';')]

红色字体处发现了这个错误的根本原因,他把命令中,我们需要用到的rsync中password对应的密码文件中赋值的=也当成了“=”
所以我们要用转意字符“\=”来处理。感觉新手在使用时,很容易碰到这个坑。


阅读(1600) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~