views:

166

answers:

1

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?

+1  A: 

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.

Alex Martelli
A direct frameless link: http://www.lag.net/paramiko/docs/paramiko.SSHClient-class.html#invoke_shell .
ΤΖΩΤΖΙΟΥ
Tx, much better.
Alex Martelli