参数和伪分配 [英] Paramiko and Pseudo-tty Allocation
问题描述
我正在尝试使用 Paramiko 连接到远程主机并执行一些文本文件替换.
I'm trying to use Paramiko to connect to a remote host and execute a number of text file substitutions.
i, o, e = client.exec_command("perl -p -i -e 's/" + initial + "/"
+ replaced + "/g'" + conf);
其中一些命令需要作为 sudo 运行,这会导致:
Some of these commands need to be run as sudo, which results in:
sudo:抱歉,你必须有一个 tty运行sudo
sudo: sorry, you must have a tty to run sudo
我可以使用 -t 开关和 ssh 强制伪 tty 分配.
I can force pseudo-tty allocation with the -t switch and ssh.
是否可以使用 paramiko 做同样的事情?
Is it possible to do the same thing using paramiko?
推荐答案
我想你想要 SSHClient
对象的 invoke_shell
方法(我很想给出一个URL 但 lag.net 上的 paramiko 文档是大量框架,不会显示给我文档中给定位置的特定 URL)--它为您提供了一个 Channel
,您可以在该频道上执行 exec_command
等操作,但是通过伪终端(完整的终端类型和行数和列数!-)这似乎是您所要求的.
I think you want the invoke_shell
method of the SSHClient
object (I'd love to give a URL but the paramiko docs at lag.net are frame-heavy and just won't show me a specific URL for a given spot in the docs) -- it gives you a Channel
, on which you can do exec_command
and the like, but does that through a pseudo-terminal (complete with terminal type and numbers of rows and columns!-) which seems to be what you're asking for.
这篇关于参数和伪分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!