no13bus
V2EX  ›  问与答

fabric 远程部署 vps 的时候,总是说:run() received nonzero return code 127 while executing。有人遇到了吗?

  •  
  •   no13bus · Aug 6, 2014 · 5124 views
    This topic created in 4305 days ago, the information mentioned may be changed or developed.
    代码如下:
    env.hosts = ['100.100.100.100']
    env.user = 'root'
    env.password = "root"
    def test():
    with cd('/tmp'):
    run('ls')
    print 'donedonedone'
    9 replies    2014-08-07 08:21:30 +08:00
    kfll
        1
    kfll  
       Aug 6, 2014 via Android
    127是命令没找到吧…试着看看环境变量
    no13bus
        2
    no13bus  
    OP
       Aug 6, 2014
    @kfll 你的意思是说vps里面的环境变量不对?
    no13bus
        3
    no13bus  
    OP
       Aug 6, 2014
    no13bus
        4
    no13bus  
    OP
       Aug 6, 2014
    siteshen
        5
    siteshen  
       Aug 6, 2014   ❤️ 1
    fabric默认使用bash执行命令,服务器上安装没有bash?
    两种解决方案:1. 服务器上安装bash(为什么这个都没有??!!);2. 参考fabric.api.run函数的文档,指定env.shell:
    run(command, shell=True, **kwargs)


    Run a shell command on a remote host.

    If ``shell`` is True (the default), `run` will execute the given command
    string via a shell interpreter, the value of which may be controlled by
    setting ``env.shell`` (defaulting to something similar to ``/bin/bash -l -c
    "<command>"``.) Any double-quote (``"``) or dollar-sign (``$``) characters
    in ``command`` will be automatically escaped when ``shell`` is True.
    no13bus
        6
    no13bus  
    OP
       Aug 7, 2014
    @siteshen 确实如此。run(command, shell=True, **kwargs)已经解决。多谢了
    no13bus
        7
    no13bus  
    OP
       Aug 7, 2014
    run(command, shell=False, **kwargs)已经解决
    dafang
        8
    dafang  
       Aug 7, 2014
    fabric 代码写的还是太多,推荐用ansible
    no13bus
        9
    no13bus  
    OP
       Aug 7, 2014 via Android
    @dafang 这还多呀。我觉得已经很少了。我看看你推荐的。多谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1233 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 17:36 · PVG 01:36 · LAX 10:36 · JFK 13:36
    ♥ Do have faith in what you're doing.