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);
Some of these commands need to be run as sudo, which results in:
sudo: sorry, you must have a tty to
run sudo
I can force pseudo-tty allocation with the -t switch and ssh.
Is it possible to do the same thing using paramiko?
I think you want the
invoke_shellmethod of theSSHClientobject (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 aChannel, on which you can doexec_commandand 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.