【问题标题】:Always given command line before python fabric command is executed on remote在远程执行 python fabric 命令之前总是给出命令行
【发布时间】:2013-09-12 23:37:12
【问题描述】:

我刚刚开始使用 python fabric 在远程 rackspace ubuntu 服务器上运行命令。如果没有需要我输入的命令行,我就无法运行命令。这是我如何重现问题的顺序。

使用 ssh 使用密钥和无密码连接到远程计算机没有任何问题。

这是我的 fabfile.py

from fabric.api import env, run

env.hosts = ['remote.ip.address']
env.user = 'http'

def hello():
    run("touch hello.world")

我用来运行 fabfile.py 的命令(使用 python 2.7 virtualenv)

$ ~/env/py27/bin/fab -f code/fabfile.py hello

这是显示它总是卡住并要求我键入 exit 的命令行。

[remote.ip.address] Executing task 'hello'
[remote.ip.address] run: touch hello.world
[remote.ip.address] out: http@server-name:~$ 

我可以通过输入 exit 退出远程终端,命令将运行,我将返回到本地终端。

[remote.ip.address] out: exit
[remote.ip.address] out: 

Done.
Disconnecting from remote.ip.address... done.
me@local-computer: $ 

这是我用来设置不需要密码的 ssh 密钥的方法。 https://kb.mediatemple.net/questions/1626/Using+SSH+keys+on+your+server

【问题讨论】:

  • 是的,这有点奇怪...您是否尝试在代码中设置主机字符串?请参阅 Toby Champion 的回答 here 了解我的意思
  • 刚刚在一个新的 Ubuntu 机器上运行了这个确切的代码。我确实需要等待一段时间才能运行。我确实添加了 env.password,接下来我可以使用密钥进行测试。
  • 已编辑问题包括我用来设置 SSH 密钥的方法。我不确定是什么导致它失败。

标签: python ubuntu deployment fabric rackspace


【解决方案1】:

有趣,我没有这样的问题,你的代码对我来说很好(直到添加 env.key_filenameenv.password

c:\work>fab hello
[x.x.x.x] Executing task 'hello'
[x.x.x.x] run: touch hello.world

Done.
Disconnecting from x.x.x.x... done.

我正在使用 Fabric 1.7.0 和 Paramiko 1.11.0。 可能是你服务器终端的问题。

【讨论】:

    【解决方案2】:

    好的,我想通了。

    我已经编辑了我的 ~/.profile 文件以包含“bash”命令,因此 bash 将成为默认 shell。我在下面复制了旧版本的 ~/.profile 文件。由于fabric 使用/bin/bash 引导它的所有命令,它本质上是启动两个bash 提示并且只退出一个。从服务器中删除 bash 命令后,一切正常。

    这是带有额外 bash 命令的 bash 文件。

    bash  #REMOVE THIS LINE AND FABRIC WORKS
    
    # if running bash
    if [ -n "$BASH_VERSION" ]; then
        # include .bashrc if it exists
        if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
        fi
    fi
    
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 2015-03-29
      • 2016-03-07
      • 1970-01-01
      • 2018-07-17
      • 2021-05-10
      • 2011-07-06
      • 2012-11-10
      • 1970-01-01
      相关资源
      最近更新 更多