我有以下fabfile:使用织物在受限shell执行命令
from fabric.api import *
env.hosts = ['samplehost']
env.user = 'foo'
env.password = 'bar'
env.shell = ''
def exec_ls():
run('ls')
run('ls -l')
,我得到下面的输出:
[samplehost] Executing task 'exec_ls'
[samplehost] run: ls
[samplehost] out: sample.txt
[samplehost] run: ls -l
[samplehost] out: rbash: ls -l: command not found
Fatal error: run() encountered an error (return code 127) while executing 'ls -l'
Aborting.
Disconnecting from samplehost... done.
的登录shell用户“富”是' /斌/ rbash”。
看来,如果我用参数执行一个命令,它将被视为单个命令(而'ls'没有参数完美工作)。
请注意,我已经放了一个空壳,因为否则Fabric会尝试使用'/ bin/bash',并且这是受限制的shell所不允许的。
是否可以在受限制的外壳中使用Fabric?
指定''rbash -l -c'',解决了这个问题。由于受限制的shell不允许使用绝对路径,所以不能放入'/ bin/rbash'。 – alexyz78 2012-02-10 15:32:03