[英]Fabric Python run command does not display remote server command “history”
I can't seem to figure this one out but when I do a very simple test to localhost to have fabric execute this command run('history') , the resulting output on the command line is blank. 我似乎无法想出这个,但是当我对localhost执行一个非常简单的测试以使结构执行此命令运行('history')时 ,命令行上的结果输出是空白的。
Nor will this work either: run('history > history_dump.log') 这也不会起作用: run('history> history_dump.log')
Here is the complete FabFile script below, obviously I'm missing something here. 下面是完整的FabFile脚本,显然我在这里遗漏了一些东西。
-- FabFile.py - FabFile.py
from fabric.api import run, env, hosts, roles, parallel, cd, task, settings, execute from fabric.operations import local,put deploymentType = "LOCAL" if (deploymentType == "LOCAL"): env.roledefs = { 'initial': ['127.0.0.1'], 'webservers': ['127.0.0.1'], 'dbservers' : ['127.0.0.1'] } env.use_ssh_config = False # Get History # ------------------------------------------------------------------------------------- @task @roles('initial') def showHistoryCommands(): print("Logging into %s and accessing the command history " % env.host_string) run('history') #does not display anything run('history > history_dump.log') #does not write anything out print "Completed displaying the command history"
Any suggestions/solutions would be most welcomed. 任何建议/解决方案都会受到欢迎。
History is a shell builtin, so it doesn't work like a normal command. 历史是内置的shell,因此它不像普通命令那样工作。 I think your best bet would be to try and read the history file from the filesystem. 我认为你最好的选择是尝试从文件系统中读取历史文件。
local('cat ~/.bash_history')
or
run('cat ~/.bash_history')
Substitute for the appropriate history file path. 替换相应的历史文件路径。
To expand a bit after some research, the command succeeds when run, but for some reason, be it that fabric neither captures or prints the output. 为了在进行一些研究之后稍微扩展一下,该命令在运行时会成功,但出于某种原因,无论是结构还是捕获或打印输出。 Or the way history prints it's output. 或者历史记录打印输出的方式。 While other builtins commands like env work fine. 而像env这样的其他内置命令工作得很好。 So for now I don't know what exactly is going on. 所以现在我不知道到底发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.